SQL - Joining tables
Hi, im having problems joining all my tables.
Everythings ok, until i add the bold lines in the sql.
code:
SELECT distinct RTRIM(
decode(c.ADDRESS1, NULL, NULL,c.ADDRESS1|| ' , ') ||
decode(c.ADDRESS2, NULL, NULL,c.ADDRESS2|| ' , ') ||
decode(c.ADDRESS3, NULL, NULL,c.ADDRESS3|| ' , ') ||
decode(c.ADDRESS4, NULL, NULL,c.ADDRESS4|| ' , ') ||
decode(c.CITY, NULL, NULL,c.CITY|| ' , ') ||
--decode(c.POSTAL_CODE, NULL, NULL,c.POSTAL_CODE|| ' , ') ||
--c.CITY,' , ') "Address" ,
c.COUNTRY, ' , ') "Address" ,
rtrim(decode(p.person_pre_name_adjunct, null, null, p.person_pre_name_adjunct||' ')||
decode(p.person_first_name, null, null,p.person_first_name||' , ')||
p.person_last_name, ' , ') "Name",
P.PARTY_ID,
p.person_number,
c.contract_number "Subscriber num",
c.item_description,
c.start_date,
c.end_date,
a.customer_class_meaning "Subscriber Type",
n.NOTES "Delivery Point"
from AMS_P_PERSON_V P, xxokb_k_details_v C, AR_CUSTOMERS_V A, AST_NOTES_DETAILS_VL N
WHERE c.PARTY_ID = p.party_id
and p.party_id = a.party_id
and c.party_id = n.source_object_id
and n.NOTE_TYPE_MEANING ='Delivery Instruction'
AND c.contract_status ='ACTIVE'
My guess is that some deliveries don't have delivery instructions, so nothing is retrieved for those rows. In which case an outer join is called for.
The other possibility is that n.source_object_id is not unique so you're getting multiple rows.
But maybe the query crashes your database due to a corrupted block. Who knows?
Similar Messages
-
Adding a filter to an SQL Join table in OBIEE
Hello,
I have created a query in OBIEE Answers to Left outer join two tables. This all works fine but I would like to set this up as a dashboard and create a prompt. The problem I have is because this is not a subject area how can I create a prompt? I would like the prompt on B.saw_2
My query is below:
SELECT
A.saw_0,
B.saw_2
FROM
(SELECT
Employee."Employee Reference" saw_0
FROM
"Applications and Awards (Employee)"
WHERE (Employee."Employee Reference" LIKE 'MR/L%')) A
LEFT OUTER JOIN
(SELECT
Employee."Employee Reference" saw_0,
LEFT(Classification."Classification Id",10) saw_1,
Classification."Classification Name" saw_2
FROM
"Applications and Awards (Employee)"
WHERE (LEFT(Classification."Classification Id",10) LIKE 'CSMRBS%')) B ON A.saw_0 = B.saw_0
Thank you,
JohnHi John,
For direct database request ::::
Please create bind variable like sql at the position of the column you are going to or want to have the value prompted. ':xyz'.
For creating prompt choose any column from any subject area, remove the formula and put dual statement like select xyz from dual. This is your value which you are passing there.
For your logical query ::: you can use presentation variable '@{xyz}123'
Thanks,
Amol
(Please mark this answer, if you found correct) -
Joining tables with SQL in Crystal XI
I am new to Crsytal Reports. I want to join 2 tables using a formula, which I am trying to do in SQL. I created a simple test report and I can get it to work if I don't put any fields on the report from the joined table. ie - if I just use fields from "sal-rep" the report works. As soon as I add a field from "freight" (my joined table) the report will not display anything. (but I don't get any error messages - just a blank report). Here is my SQL:
SELECT "sal-rep"."full-name","sal-rep"."invoice-nbr","freight"."misc-charge-ammount" FROM "PUB"."sal-rep" INNER JOIN "PUB"."FREIGHT" ON ("sal-rep"."invoice-nbr"="freight"."invoice-nbr") WHERE "sal-rep"."invoice-nbr"='0000189957'I got it to work!!! This is the SQL I used -
SELECT "sal_rep"."full-name", "sal_rep"."invoice-nbr", "freight"."misc-charge-ammount", "freight"."invoice-date"
FROM "PUB"."freight" "freight" INNER JOIN "PUB"."sal-rep" "sal_rep" ON ("freight"."invoice-nbr"="sal_rep"."invoice-nbr") AND ("freight"."invoice-date"="sal_rep"."inv-date")
WHERE "sal_rep"."invoice-nbr"='0000189957'
Now when I look at the Table used in Database expert it lists - Command and Freight.
Before it was listing Command and Sal-Rep.
Not sure I understand why, but at least it's working.
thanks for your help - really appreciated! -
How to provide joins between oracle tables and sql server tables
Hi,
I have a requirement that i need to generate a report form two different data base. i.e Oracle and Sql Server.
how to provide joins between oracle tables and sql server tables ? Any help on this
Regards,
Malliuser10675696 wrote:
I have a requirement that i need to generate a report form two different data base. i.e Oracle and Sql Server. Bad idea most times. Heterogeneous joins do not exactly scale and performance can be severely degraded by network speed and b/w availability. And there is nothing you can do in the application and database layers to address performance issue at the network level in this case - your code's performance is simply at the mercy of network performance. With a single glaring fact - network performance is continually degrading. All the time. Always. Until it is upgraded. When the performance degradation starts all over again.
If the tables are not small (few 1000 rows each) and row volumes static, I would not consider doing a heterogeneous join. Instead I would rather go for a materialised view on the Oracle side, use a proper table and index structure, and do a local database join. -
hi there..i need ur helps
Here are my tables n column name for each tables
a) rep_arrngt
Name
REP_ARRNGT_ID
REP_ARRNGT_DESC
REP_ARRNGT_TYPE
ACCT_CAT
DEF_INDUSTRY_CODE
MEDIA_ID
LANGUAGE_ID
CURRENCY
PAGE_ID
b) bci_rep_arrng
Name
REP_ARRNGT_ID
BCI
SUB_SUM_CODE
DP_SUB_SUM_CODE
c) acct_rep_arrngt_link
Name
ACCT_NO
REP_ARRNGT_ID
DOC_TYPE
LAST_BILL_DATE
BILL_FREQUENCY
SCALING
EFF_FROM_DATE
EFF_TO_DATE
MEDIA_ID
Actually, i want to get the unique value for sub_sum_code according to the bci..
i already use join tables n here is my sql statement :
SELECT T1.SUB_SUM_CODE,T1.BCI,T1.REP_ARRNGT_ID,T2.REP_ARRNGT_ID,T3.REP_ARRNGT_ID FROM BCI_REP_ARRNG T1, REP_ARRNGT T2, ACCT_REP_ARRNGT_LINK T3 WHERE T1.REP_ARRNGT_ID=T2.REP_ARRNGT_ID AND T2.REP_ARRNGT_ID=T3.REP_ARRNGT_ID AND BCI='TTA00F06'
n my results is :
SUB_SUM_CODE BCI REP_ARRNGT_ID
TBGSR TTA00F06 R1
TBGSR TTA00F06 R1
TBGSR TTA00F06 R1
TBGSR TTA00F06 R1
I get the repeated results for sub_sum_code..
so, what i need to do if i want only 1 row results like this :
[u]SUB_SUM_CODE BCI REP_ARRNGT_ID
TBGSR TTA00F06 R1
i try to use group by, but i get the error..plz help meIf you only want "to get the unique value for sub_sum_code according to the bci" then why are you joining the tables in the first place? Not knowing PKs etc you could just use DISTINCT in your select statement.
SELECT DISTINCT T1.SUB_SUM_CODE,
T1.BCI
FROM BCI_REP_ARRNG T1
AND BCI='TTA00F06' -
What is the better way to join table for ASE 12.5?
To join table with T-SQL, there are 2 options:
select * from tab1 a join tab2 b on a.id = b.id where x=y
select * from tab1a, tab2 b where a.id = b.id and x=y
this is only a syntax difference or there is a performance difference? which one is better for performance?The first query (using the join clause) is the ANSI standard way of writing joins and is usually supported by all mainstream RDBMSs.
The second query is the T-SQL method of writing joins and may have limited re-usability with other RDBMSs.
In most cases which one you use is usually one of preference, ie, which ever one you're comfortable with.
From a technical perspective there are some join constructs that you cannot build with T-SQL joins, but can build with ANSI joins (eg, you may have problems in T-SQL with a table that you want to be both a) an inner table of an outer join and b) part of a equi/inner join).
Soooo, ANSI joins provide you a lot more flexibility in coding as well as portability (between other RDBMSs). But if you're going to work with ASE you'll still need to understand how T-SQL joins work as you'll see quite a lot of T-SQL join-based queries. -
How can I pass multiple condition in where clause with the join table?
Hi:
I need to collect several inputs at run time, and query the record according to the input.
How can I pass multiple conditions in where clause with the join table?
Thanks in advance for any help.
Regards,
TDIf you are using SQL-Plus or Reports you can use lexical parameters like:
SELECT * FROM emp &condition;
When you run the query it will ask for value of condition and you can enter what every you want. Here is a really fun query:
SELECT &columns FROM &tables &condition;
But if you are using Forms. Then you have to change the condition by SET_BLOCK_PROPERTY.
Best of luck! -
How to use a MAP whithout join table
Hello
I am still evaluating KODO ;-)
I am using kodo 3.1.2 with an evaluation version
linux (kernel 2.6)
SUN JDK 1.4.2_04
MYSQL MAX 4.0.18 -Max
IDEA 4.0.3 and ANT 1.5.4 (to be exhaustive)
I am wondering how to configure the following mapping involving a Map. :
public class Translation {
private String locale;
private String txt;
public class TranslatableDescription {
/**Map of Key=locale as String; Value = {@link Translation}*/
==> private Map translations = new HashMap(); <==
public void addATranslation(Translation t){
translations.put(t.getLocale(), t);
file package.jdo :
<?xml version="1.0"?>
<jdo>
<package name="data">
<class name="Translation"/>
<class name="TranslatableDescription">
<field name="translations">
<map key-type="java.lang.String"
value-type="tutorial.data.Translation"/>
<extension vendor-name="kodo" key="jdbc-key-size" value="10"/>
</field>
</class>
</package>
</jdo>
The default Mapping generate a join table : TRANS_TRANSLATION which works
fine, but I would like to remove this table by adding a
colonne in the "TRANSLATION" table containing the JDOID of the
TRANSLATIONDESCRIPTION owner of this TRANSLATION.
I have made some try like this one in the mapping file
<class name="TranslatableDescription">
<field name="translations">
<jdbc-field-map type="n-many-map" key-column="LOCALE"
ref-column.JDOID="OWNERJDOID" table="TRANSLATION0"
value-column.JDOID="JDOID"/>
</field>
The schema generated in my DB is correct but when I try to persist some
objects I have the following Exception :
727 INFO [main] kodo.jdbc.JDBC - Using dictionary class
"kodo.jdbc.sql.MySQLDictionary" (MySQL 4.0.18'-Max' ,MySQL-AB JDBC Driver
mysql-connector-java-3.0.10-stable ( $Date: 2004/01/13 21:56:18 $,
$Revision: 1.27.2.33 $ )).
Exception in thread "main" kodo.util.FatalDataStoreException: Invalid
argument value, message from server: "Duplicate entry '2' for key 1"
{prepstmnt 8549963 INSERT INTO TRANSLATION0 (JDOID, LOCALESTR, OWNERJDOID)
VALUES (?, ?, ?) [reused=0]} [code=1062, state=S1009]
NestedThrowables:
com.solarmetric.jdbc.ReportingSQLException: Invalid argument value,
message from server: "Duplicate entry '2' for key 1" {prepstmnt 8549963
INSERT INTO TRANSLATION0 (JDOID, LOCALESTR, OWNERJDOID) VALUES (?, ?, ?)
[reused=0]} [code=1062, state=S1009]
java.sql.BatchUpdateException: Invalid argument value, message from
server: "Duplicate entry '2' for key 1"
at kodo.jdbc.sql.SQLExceptions.getFatalDataStore(SQLExceptions.java:42)
at kodo.jdbc.sql.SQLExceptions.getFatalDataStore(SQLExceptions.java:24)
at kodo.jdbc.runtime.JDBCStoreManager.flush(JDBCStoreManager.java:594)
at
kodo.runtime.DelegatingStoreManager.flush(DelegatingStoreManager.java:152)
at
kodo.runtime.PersistenceManagerImpl.flushInternal(PersistenceManagerImpl.java:964)
at
kodo.runtime.PersistenceManagerImpl.beforeCompletion(PersistenceManagerImpl.java:813)
at kodo.runtime.LocalManagedRuntime.commit(LocalManagedRuntime.java:69)
at
kodo.runtime.PersistenceManagerImpl.commit(PersistenceManagerImpl.java:542)
at
tutorial.CreateTranslatableDescription.main(CreateTranslatableDescription.java:48)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at com.intellij.rt.execution.application.AppMain.main(Unknown Source)
I have the feeling that KODO does try to make diffent row in the table
"TRANSLATION0" for the TRANSLATION and the MAP.
So, is this kind of mapping supported by KODO and if yes, how can I
configure it.
Thank you for your help
NicolasSo, is this kind of mapping supported by KODO and if yes, how can I
configure it.It is not directly supported. You can fake it using a one-many mapping
(see thread: Externalizing Map to Collection of PC), but unless you must
map to an existing schema, it's probably not worth the effort. (Note:
also there is a bug that actually prevents this from working with 3.1.2;
the bug is fixed for 3.1.3, but it hasn't been released yet). -
I am beginner in MVC and I would like to create a view which populates two (or more) joined tables in a single view table as described below.
I have two tables:
1 - Bloggers: - bloggerID (int);
- bloggerName (string)
2 - Blogs: - blogID (int);
bloggerID (int);
- blogTitle (string);
- blogImage (string)
A blogger can have one or more blogs while one blog must be related to only one blogger.
I would like to have a view table on my webpage as the following:
Blogger Name
Blog Title
Blog Image
Noris Gang
Virus
virus.jpg
Noris Gang
Desktops
desktop.jpg
Gauthier
Books
books.png
John Leon
NNNMHJhjdhj
Nmbj.jpg
I'm using MVC 4 (or at least 3).
Thanks for your help.Hello,
From your description, it is not very clear that what you mean about the View, if it means the View concept in database as SQL Server, your required view should be as below:
Create view
as
Select Bloggers.bloggerName, Bloggers.blogTitle, Bloggers.blogImage
From Bloggers join Blogs on Bloggers.bloggerID = Blogs. bloggerID
If it means the UI view in MVC concept, I suggest you could ask it on the MVC forum:
http://forums.asp.net/1146.aspx
Regards.
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click
HERE to participate the survey. -
SQL Join help for multiple values in single field.
Hello All,
I need a help, I have two tables T1 and T2
Content of T2 will be like
T2. ID | T2.USERNAME
ID1 | John
ID2 | Peter
ID3 | Mark
Content of T1 is like
T1.ID
ID1 ID2 ID3
ID2
ID1 ID3
I need to join these two tables and replace the T1.ID values with T2.USERNAME, for eg. Row one of T1 should be changed as John Peter Mark.
Note: ID1 ID2 ID3 is a single value.
Thanks for your help.
Sathish.At Volder: I have made a slight enhancement. It's the same thing but the other way around as last week's regular expression thread. Remember the "and then the bird flew away"? ;-)
SQL> create table t1
2 as
3 select 'ID1 ID2 ID3' id from dual union all
4 select 'ID2' from dual union all
5 select 'ID1 ID3' from dual union all
6 select 'ID11 ID2' from dual
7 /
Tabel is aangemaakt.
SQL> create table t2
2 as
3 select 'ID1' id, 'John' username from dual union all
4 select 'ID2', 'Peter' from dual union all
5 select 'ID3', 'Mark' from dual union all
6 select 'ID11', 'Volder' from dual
7 /
Tabel is aangemaakt.
SQL> select * from t1
2 model
3 reference r on (select t2.*, rownum rn from t2)
4 dimension by (rn)
5 measures(id, username)
6 main m
7 dimension by (id)
8 measures(cast(id as varchar(200)) str)
9 rules iterate(100) until (r.id[iteration_number+1] is null)
10 (str[any] = replace(str[CV()], r.id[iteration_number+1],r.username[iteration_number+1]))
11 /
ID STR
ID1 ID2 ID3 John Peter Mark
ID2 Peter
ID1 ID3 John Mark
ID11 ID2 John1 Peter
4 rijen zijn geselecteerd.
SQL> select id
2 , str
3 from t1
4 model
5 reference r on (select id,username,rownum rn from t2)
6 dimension by (rn)
7 measures (id, username)
8 main m
9 dimension by (id)
10 measures (cast(' ' || id || ' ' as varchar2(200)) str)
11 rules iterate(1000) until (r.id[iteration_number+1] is null)
12 ( str[any] = replace
13 ( str[cv()]
14 , ' ' || r.id[iteration_number+1] || ' '
15 , ' ' || r.username[iteration_number+1] || ' '
16 )
17 )
18 /
ID STR
ID1 ID2 ID3 John Peter Mark
ID2 Peter
ID1 ID3 John Mark
ID11 ID2 Volder Peter
4 rijen zijn geselecteerd.At Sathish: just look at the queries we have to come up with to do such a simple thing. As said many times before, I would also encourage you to change the design instead of executing the queries presented by Volder and me.
Regards,
Rob.
Message was edited by:
Rob van Wijk
Just noticed I missed a final TRIM function around "str", so please add this. -
DB connectivi​ty toolkit: syntax error in a SELECT data from joined tables
Hello everyone
I'm trying to put in labview an SQL query on joined tables.
As example I take a DB for storing the data of 2on2 basketball games, whose tables are
matches(matchId,teamA,teamB)
teams(teamId,PlayerAname,PlayerBname,Nationality)
nationalities(NatId,natName)
To get a result table with the match number and the player names along with their nationality I use this query on MySQL (which works on the command line interface)
SELECT MatchID,
t1.PlayerAName, t1.PlayerBName, n1.natName,
t2.PlayerAName, t2.PlayerBName, n2.natName
FROM matches m
INNER JOIN teams t1 ON t1.teamID = m.teamA
INNER JOIN teams t2 ON t2.teamID = m.teamB
INNER JOIN nationalities n1 ON n1.natID = t1.nationality
INNER JOIN nationalities n2 ON n2.natID = t2.nationality
When I put it in labview, using the "select data" block, I get a syntax error as shown in the attached screenshot.
Am I mistanking something in using the JOIN statements, or the aliases?
Thanks in advance!
Solved!
Go to Solution.
Attachments:
select2dabone.vi 12 KBGiovasa wrote:
I do't like very much the chain of blocks execute query+n*(fetch element)+free object, so I try to avoid that as much that I can...
Sounds like a prime candidate for a subVI. You don't have to use it every time, but it probably would help for cases where you do want to put the SQL query directly in code.
Incidentally, if you're doing joins, you might consider using views, as that allows you to hide the details of the interactions of the tables in the DB itself.
Try to take over the world! -
SQL JOIN with BPM sql component
Hello friends.
How to use SQL JOIN with BPM sql component?
The tables objects are created but the joined tables belong to different sql components .
I tried something like that, but a error "table doesn't exist" occours.
Ex:
for each element in
SELECT imuImovelCd
FROM IMOVEIS_URBANOS,
Integracao.FGLP.IMOVEIS_PRE_EDITAIS
WHERE IMOVEIS_URBANOS.imuImovelCd = Integracao.FGLP.IMOVEIS_PRE_EDITAIS.ipeImuCd
AND Integracao.FGLP.IMOVEIS_PRE_EDITAIS.ipePedNr = 1
AND Integracao.FGLP.IMOVEIS_PRE_EDITAIS.ipePedAa = 2008
do
extend this.imoveis using cdImovel = element.imuimovelcd,
nrImovel = call(DEC_ENDERECO, codimovel : element.imuimovelcd, tipoimovel : 1)
end
Edited by: user9008295 on 26/01/2010 05:19ok, ok you are right.
When I try use SQL Statement to make a JOIN with 2 tables on different sql objects, BPM returns "table dosn't exists".
So.... I change my code. I dont know if this is the best way to do, but... i hope u, or everyone, can help me to do a best work.
This code works fine.
for each element in
SELECT ipeImuCd
FROM Integracao.FGLP.IMOVEIS_PRE_EDITAIS
WHERE Integracao.FGLP.IMOVEIS_PRE_EDITAIS.ipePedNr = 1
AND Integracao.FGLP.IMOVEIS_PRE_EDITAIS.ipePedAa = 2008
do
for each element2 in
SELECT imuImovelDv
FROM IMOVEIS_URBANOS
WHERE imuImovelCd = element.ipeImuCd
do
extend this.imoveis using cdDvImovel = String(element2.imuImovelDv),
cdImovel = Decimal(element.ipeImuCd),
endereco = call(DEC_ENDERECO, codimovel : element.ipeImuCd, tipoimovel : 1)
end
end
Thx a lot!!! -
Hi all.
I am learning join- tables in SQL.
My question relates to the use of WHERE. It is probably best if I show 2 examples:
1 SELECT ename, dname from emp e join dept d on (e.deptno = d.deptno) WHERE ename = 'Jones';
2 SELECT ename, dname from emp e, dept d where e.deptno = d.deptno
So the question is: How do I stipulate in Example 2 that I want the details returned for 'jones' ?
I have tried using AND WHERE, but it doesn't seem to work.
Any thoughts??Just answered my own Q.!!
2 SELECT ename, dname from emp e, dept d where e.deptno = d.deptno AND ename = 'jones'
Sometimes the simplest solution works.
I have clicked answered. I presume that you cannot obtain points for answering your own question!? -
Oracle equivalent to SQL Server Table Variables ?
Does Oracle have anything equivalent to SQL Server table variables, that can be used in the JOIN clause of a select statement ?
What I want to do is execute a query to retrieve a two-column result, into some form of temporary storage (a collection ?), and then re-use that common data in many other queries inside a PL/SQL block. I could use temporary tables, but I'd like to avoid having to create new tables in the database, if possible. If I was doing this in SQL Server, I could use a table variable to do this, but is there anything similar in Oracle ? SQL Server example:
use Northwind
DECLARE @myVar TABLE(CustomerID nchar(5), CompanyName nvarchar(40))
INSERT INTO @myVar(CustomerID, CompanyName)
select CustomerID, CompanyName
from Customers
--Join the variable onto a table in the database
SELECT *
FROM @myVar mv join Customers
on mv.CompanyName = Customers.CompanyName
The closest I've found in Oracle is to use CREATE TYPE to create new types in the database, and use TABLE and CAST to convert the collection to a table, as shown below. I can't see anyway without creating new types in the database.
CREATE TYPE IDMap_obj AS Object(OldID number(15), NewID number(15));
CREATE TYPE IDMap_TAB IS TABLE OF IDMap_obj;
DECLARE
v_Count Number(10) := 0;
--Initialize empty collection
SourceIDMap IDMap_TAB := IDMap_TAB();
BEGIN
--Populate our SourceIDMap variable (dummy select statement for now).
FOR cur_row IN (select ID As OldID, ID + 10000000 As NewID From SomeTable) LOOP
SourceIDMap.extend;
SourceIDMap(SourceIDMap.Last) := IDMap_obj(cur_row.OldId, cur_row.NewId);
END LOOP;
--Print out contents of collection
FOR cur_row IN 1 .. SourceIDMap.Count LOOP
DBMS_OUTPUT.put_line(SourceIDMap(cur_row).OldId || ' ' || SourceIDMap(cur_row).NewId);
END LOOP;
--OK, can we now use our collection in a JOIN statement ?
SELECT COUNT(SM.NewID)
INTO v_Count
FROM SomeTable ST JOIN
TABLE(CAST(SourceIDMap As IDMap_TAB)) SM
ON ST.ID = SM.OldID;
DBMS_OUTPUT.put_line(' ' );
DBMS_OUTPUT.put_line('v_Count is ' || v_Count);
END;Hi, got this from our plsql guys:
The term "table function" is a bit confusing here. In Oracle-speak, it means a function that can be used in the from list of a select statement thus:
select * from Table(My_Table_Function()),..
where...
The function's return type must be a collection that SQL understands. So for the interesting case -- mimicking a function with more than one column -- this would be a nested table of ADTs where both the ADT and the nested table are defined at schema level. PL/SQL -- by virtue of some clever footwork -- allows you to declare the type as a nested table of records where both these types are declared in a package spec. This alternative is generally preferred, especially because the nested table can be of Some_Table%rowtype (or Some_Cursor%rowtype if you prefer).
As I understand it from our man on the ANSI committee, our use terminology follows the standard.
The construct below seems to be a bit different (though there are similarities) because it appears from your code sample that it's usable only within procedural code. And the object from which you select is a variable rather than a function.
So, after that preamble... the answer would be:
No, we don't have any constructs to let you "declare" something that looks like a regular schema-level table as a PL/SQL variable -- and then use (static) SQL on it just as if it were a schema-level table.
But yes, you can use PL/SQL's pipelined table function to achieve much of the same effect.
Look at the attached Table_Function.sql.
It shows that you can populate a collection of records using ordinary PL/SQL code. You can't use SQL for insert, update, or delete on such a collection. I see that SQL Server lets you do
insert into Program_Variable_Table select... from Schema_Level_Table
The PL/SQL equivalent would be
select...
bulk collect into Program_Variable_Collection
from Schema_Level_Table
The attached shows that once you have populated your collection, then you can then query it with regular SQL -- both from inside PL/SQL code and from naked SQL.
and the code is here
CONNECT System/p
-- Drop and re-create "ordinary" user Usr
EXECUTE d.u
CONNECT Usr/p
create table Schema_Things(ID number, Description Varchar2(80))
create package Pkg is
subtype Thing_t is Schema_Things%rowtype;
type Things_t is table of Thing_t; -- index by pls_integer
Things Things_t;
-- PLS-00630: pipelined functions must have
-- a supported collection return type
-- for "type Things_t is table of Thing_t index by pls_integer".
function Computed_Things return Things_t pipelined;
procedure Insert_Schema_Things(No_Of_Rows in pls_integer);
end Pkg;
create package body Pkg is
function Computed_Things return Things_t pipelined is
Idx pls_integer;
Thing Thing_t;
begin
Idx := Things.First();
while Idx is not null loop
pipe row (Things(Idx));
Idx := Things.Next(Idx);
end loop;
end Computed_Things;
procedure Insert_Schema_Things(No_Of_Rows in pls_integer) is
begin
Things := Things_t();
Things.Extend(No_Of_Rows);
for j in 1..No_Of_Rows loop
Things(j).ID := j;
Things(j).Description := To_Char(j, '00009');
end loop;
insert into Schema_Things
select * from Table(Pkg.Computed_Things());
end Insert_Schema_Things;
end Pkg;
-- Test 1.
begin Pkg.Insert_Schema_Things(100); end;
select * from Schema_Things
-- Test 2.
begin
Pkg.Things := Pkg.Things_t();
Pkg.Things.Extend(20);
for j in 1..20 loop
Pkg.Things(j).ID := j;
Pkg.Things(j).Description := To_Char(j, '00009');
end loop;
for j in 1..5 loop
Pkg.Things.Delete(5 +2*j);
end loop;
end;
select * from Table(Pkg.Computed_Things())
/ -
Hi everybody,
I have read the SQL Tuning section of Performance Tuning Oracle Book of Oracle 10g. v.2.
In 11.5.4. paragraph titled "Controlling the Access Path and Join Order with Hints" , in the second note there is a small paragraph about the right join of the tables....
In whichever query i try ,i've noticed that altering the joining order of the tables the sql statistics (consistent gets , sorts(memory/disk)) are the same regardless of the join order....
Can you please give me an example or a source in which the modification of the join order of the tables in a sql query produce different results ...in statistics????
Thanks , a lot
SimonDuplicate post. Don't answer this thread please Right order of joining tables.
Cheers, APC
Maybe you are looking for
-
Oracle 8i, Getting ORA-1501 error while creating new DB
Hi folks, I am trying create a new database on an HP Machine (Details given below) but getting following error. ORA-1501 - signalled during Create Database LOGFILE 'G:\logfiles\logaf1.ora' We actually have a custom application setup.exe to create new
-
Dear Firefox: It's official - I've divorced you
October 11, 2011 Dear Firefox: It has been a long and, up until recently, a very happy marriage between you and me. However, your recent screw-ups have caused me to file for, and finalize, our divorce. This was done without your comment or consent, I
-
BOE XI 3.1: How to batch delete 10,000+ history files?
Hi, Does anyone know how to batch delete 10,000+ history files? Thanks, Vicky
-
My iphoto is incomplete and damaged. How can I fix this problem?
I have mac 10.7.5. I installed ilife from a disc but can not find it. I believe it corupted my iphoto... My main problem is I now can not open iphoto due to being 'damaged' and 'incomplete'. Can someone please explain to me what steps can i take to g
-
Nexus1000v - ? communication issue vcenter - N1Kv ???
Unregulary we get these kind of alarms in our vcenter although there were no changes made on nexus or VM side.: "vSphere HA detected that host HOSTNAME is in a different network partition than the master MASTERNAME" They are cleared