Cartesian Join of xmltables.
Hi,
SQL> var xml varchar2(3999)
SQL> begin
2 :xml := '<X12 NAME="856.edi">
3 <ISA01>00</ISA01>
4 <ISA02>XXXXXXXXXX</ISA02>
5 <ISA03>00</ISA03>
6 <ISA04>XXXXXXXXXX</ISA04>
7 <ISA05>ZZ</ISA05>
8 <ISA ID="552101">
9 <GS01>SH</GS01>
10 <GS02>xxxxxxxx</GS02>
11 <GS03>xxxxxxxxx</GS03>
12 <GS04>20060815</GS04>
13 <GS05>015219</GS05>
14 <GS06>xxxxxxxxxx</GS06>
15 <GS07>X</GS07>
16 <GS08>004010</GS08>
17 <GS ID="552102">
18 <ST01>856</ST01>
19 <ST02>0001</ST02>
20 <ST ID="552103">
21 <LIN>
22 <LIN02>IN</LIN02>
23 <LIN03>9D00025443</LIN03>
24 <LIN04>PO</LIN04>
25 <LIN05>25254404</LIN05>
26 </LIN>
27 <SN1>
28 <SN102>552</SN102>
29 <SN103>EA</SN103>
30 </SN1>
31 <LIN>
32 <LIN02>IN</LIN02>
33 <LIN03>9D00025443</LIN03>
34 <LIN04>PO</LIN04>
35 <LIN05>25255149</LIN05>
36 </LIN>
37 <SN1>
38 <SN102>1104</SN102>
39 <SN103>EA</SN103>
40 </SN1>
41 <CTT>
42 <CTT01>9</CTT01>
43 </CTT>
44 <SE>
45 <SE01>38</SE01>
46 <SE02>0001</SE02>
47 </SE>
48 </ST>
49 </GS>
50 <GE>
51 <GE01>1</GE01>
52 <GE02>913823084</GE02>
53 </GE>
54 <IEA>
55 <IEA01>1</IEA01>
56 <IEA02>913823084</IEA02>
57 </IEA>
58 </ISA>
59 </X12>';
60 end;
61 /
PL/SQL procedure successfully completed.
SQL> set long 32000
SQL> SELECT VALUE (i).EXTRACT ('/*')
2 FROM
3 TABLE (XMLSEQUENCE (EXTRACT (XMLTYPE (:xml), '/X12/ISA/GS/ST'))) k,
4 TABLE (XMLSEQUENCE (EXTRACT (VALUE (k), '/ST/LIN'))) i;
VALUE(I).EXTRACT('/*')
<LIN>
<LIN02>IN</LIN02>
<LIN03>9D00025443</LIN03>
<LIN04>PO</LIN04>
<LIN05>25254404</LIN05>
</LIN>
<LIN>
<LIN02>IN</LIN02>
<LIN03>9D00025443</LIN03>
<LIN04>PO</LIN04>
<LIN05>25255149</LIN05>
</LIN>
SQL>
SQL> SELECT VALUE (i).EXTRACT ('/*')
2 FROM
3 TABLE (XMLSEQUENCE (EXTRACT (XMLTYPE (:xml), '/X12/ISA/GS/ST'))) k,
4 TABLE (XMLSEQUENCE (EXTRACT (VALUE (k), '/ST/LIN'))) i,
5 TABLE (XMLSEQUENCE (EXTRACT (VALUE (k), '/ST/SN1'))) m;
VALUE(I).EXTRACT('/*')
<LIN>
<LIN02>IN</LIN02>
<LIN03>9D00025443</LIN03>
<LIN04>PO</LIN04>
<LIN05>25254404</LIN05>
</LIN>
<LIN>
<LIN02>IN</LIN02>
<LIN03>9D00025443</LIN03>
<LIN04>PO</LIN04>
<LIN05>25254404</LIN05>
</LIN>
<LIN>
<LIN02>IN</LIN02>
<LIN03>9D00025443</LIN03>
<LIN04>PO</LIN04>
<LIN05>25255149</LIN05>
</LIN>
<LIN>
<LIN02>IN</LIN02>
<LIN03>9D00025443</LIN03>
<LIN04>PO</LIN04>
<LIN05>25255149</LIN05>
</LIN>I am trying to put the LIN and SN1 segment into one row. But, when I do it this way, it is giving me cartesian join. I tried doing this using XMLTable operator too. I couldn't get anywhere.
Look at the example of the manual (XMLDB Developers Guide) regarding the use of XMLQuery and XMLTable: Example 17-12 Using XMLTable to Shred XML Collection Elements into Relational Data
or given the following example, can you work it out now for your situation?
SQL*Plus: Release 10.2.0.2.0 - Production on Tue Oct 10 20:52:53 2006
Copyright (c) 1982, 2005, Oracle. All Rights Reserved.
SQL> @login
SQL> conn oe/[email protected]
Connected.
SQL> select * from v$version;
BANNER
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod
PL/SQL Release 10.2.0.1.0 - Production
CORE 10.2.0.1.0 Production
TNS for 32-bit Windows: Version 10.2.0.1.0 - Production
NLSRTL Version 10.2.0.1.0 - Production
5 rows selected.
SQL> CREATE OR REPLACE VIEW purchaseorder_detail_view AS
2 SELECT po.reference, li.*
3 FROM purchaseorder p,
4 XMLTable('/PurchaseOrder' PASSING p.OBJECT_VALUE
5 COLUMNS
6 reference VARCHAR2(30) PATH 'Reference',
7 lineitem XMLType PATH 'LineItems/LineItem') po,
8 XMLTable('LineItem' PASSING po.lineitem
9 COLUMNS
10 itemno NUMBER(38) PATH '@ItemNumber',
11 description VARCHAR2(256) PATH 'Description',
12 partno VARCHAR2(14) PATH 'Part/@Id',
13 quantity NUMBER(12, 2) PATH 'Part/@Quantity',
14 unitprice NUMBER(8, 4) PATH 'Part/@UnitPrice') li;
View created.
SQL> desc purchaseorder_detail_view
Name Null? Type
REFERENCE VARCHAR2(30)
ITEMNO NUMBER(38)
DESCRIPTION VARCHAR2(256)
PARTNO VARCHAR2(14)
QUANTITY NUMBER(12,2)
UNITPRICE NUMBER(8,4)
SQL> select * from purchaseorder_detail_view
1 where rownum <= 10;
REFERENCE ITEMNO DESCRIPTION PARTNO QUANTITY UNITPRICE
CJOHNSON-20021009123337283PDT 1 Rushmore 715515010429 1 39.95
CJOHNSON-20021009123337283PDT 2 The Magic Flute 37429147528 2 29.95
CJOHNSON-20021009123337283PDT 3 How to Get Ahead in Advertising 715515012324 1 29.95
CJOHNSON-20021009123337283PDT 4 Written on the Wind 715515011525 3 29.95
CJOHNSON-20021009123337283PDT 5 Spartacus 715515011723 2 39.96
CJOHNSON-20021009123337283PDT 6 The Hidden Fortress 37429135129 2 29.95
CJOHNSON-20021009123337283PDT 7 Amarcord 37429121825 1 39.95
CJOHNSON-20021009123337283PDT 8 The Harder They Come 715515010825 3 39.95
CJOHNSON-20021009123337283PDT 9 George Washington 37429166123 2 39.95
CJOHNSON-20021009123337283PDT 10 Sanjuro 37429141526 1 29.95
10 rows selected.
Message was edited by:
mgralike
Similar Messages
-
Grus help needed in finding the queries with Cartesian joins
Hi
I have a reporting tool in which users are allowed to put the joins on the views and add some sub queries that produces a Cartesian product. Is there any tool or way that I can stop the execution of those query before it is being executed for example
Step 1 ) user creates a query
step2 ) user submits it
step 3) by any tool or any check if Cartesian join is found the query execution is stopped and notify the user that the query is not good if no problem executes the query.
I really need help in step 3. I am on 9i release2.
Any help or suggestions will be highly appreciated.I Agree with Gasparotto, you should limit the resource consume.
You must understand that cartesian join, isn´t always a BAD guy, sometimes you need it.
If your developers are in trouble with handle the join , think about NATURAL JOIN, may be it helps you
Regards
Helio Dias -
Hi friends,
I need to restrict the report according to the user who logs in to the application. But only for the ADMIN user i need to show all the records except with the status which is not in "CREATED', i need to show all the records to the admin with other status other than the 'CREATED" status.
For that i tried with the below query
select
'' "Null",
"REQUEST_ID",
"REQUEST_TYPE_NAME",
"REQUEST_NUMBER",
"REQUEST_CLASS_NAME",
"REQUEST_STATUS_NAME",
"REQUEST_DATE"
from XXHY_AMS_REQ_DET_V , apps.fnd_user xx
where /*request_number like nvl(:P1_REQUEST_NUMBER,'%')
and
REQUEST_STATUS_CODE like nvl(:P1_REQUEST_STATUS,'%')
and
lower(REQUEST_DATE) LIKE NVL(lower(:P1_REQUEST_DATE), '%')
and */requestor_person_id = xx.employee_id or
lower(xx.user_name) = lower(:APP_USER) or
exists (select 1 from apps.per_all_people_f papf,
apps.per_all_assignments_f paaf,
apps.per_all_people_f supf,
apps.pqh_roles rls,
apps.per_people_extra_info pei,
apps.fnd_user a, XXHY_AMS_REQ_DET_V b
where papf.person_id = paaf.person_id and pei.person_id = paaf.person_id
and nvl(paaf.supervisor_id, papf.person_id) = supf.person_id
and sysdate between papf.effective_start_date and papf.effective_end_date
and sysdate between paaf.effective_start_date and paaf.effective_end_date
and sysdate between supf.effective_start_date and supf.effective_end_date
and a.employee_id = papf.person_id
and lower(a.user_name) = lower(:APP_USER)
and information_type = 'PQH_ROLE_USERS' and paaf.person_id = b.requestor_person_id and lower(b.request_status_code) not in ('created')
and rls.role_id = to_number (pei.pei_information3)
and rls.role_id = to_number (pei.pei_information3) and rls.role_name like 'XXHW_AMS_ADMIN')
order by 1
In the above query i used the keyword :APP_USER which identifies the user who logs in APEX.
Also i have a role named XXHW_AMS_ADMIN, which identifies the user under the admin category.
So, according to my query, if the user is not in the admin category means, it has to show only the records raised by him. If the user is in the admin category means then it has to show all the records of all the users other than the status which is not in 'CREATED'.
But my above query is resulting in cartesian join, if i check with the admin username.
But it fetches the correct result if i checked with the user who is not in the admin category.
I dont know why the cartesian join is occuring if i check with the admin user.
Suppose if i tried to run the query separately which is beneath the EXIST condition* for checking the admin user means, then it is recognizing the admin. But i dont know why it is not working in my above query.*
select 1 from apps.per_all_people_f papf,
apps.per_all_assignments_f paaf,
apps.per_all_people_f supf,
apps.pqh_roles rls,
apps.per_people_extra_info pei,
apps.fnd_user a, XXHY_AMS_REQ_DET_V b
where papf.person_id = paaf.person_id and pei.person_id = paaf.person_id
and nvl(paaf.supervisor_id, papf.person_id) = supf.person_id
and sysdate between papf.effective_start_date and papf.effective_end_date
and sysdate between paaf.effective_start_date and paaf.effective_end_date
and sysdate between supf.effective_start_date and supf.effective_end_date
and a.employee_id = papf.person_id
and lower(a.user_name) = lower(:APP_USER)
and information_type = 'PQH_ROLE_USERS' and paaf.person_id = b.requestor_person_id and lower(b.request_status_code) not in ('created')
and rls.role_id = to_number (pei.pei_information3)
and rls.role_id = to_number (pei.pei_information3) and rls.role_name like 'XXHW_AMS_ADMIN')
order by 1what might be wrong in my query.
Brgds,
MiniI was using SQL Developer so i used colon.
For Sql plus I changed it to & and it is working as expected
SQL> with t_user as
select 1 as person_id, 'P1' as user_name from dual union all
select 2,'P2' from dual union all
select 3,'P3' from dual union all
select 4,'P4' from dual union all
select -1,'ADMIN' from dual
t_req_data as
select 1 as person_id, 'created' as request_status_code, sysdate-1 as some_data from dual union all
select 1 , 'updated' , sysdate-0.5 from dual union all
select 2 , 'deleted' , sysdate from dual union all
select -1 , 'created' , sysdate from dual union all
select -1 , 'updated' , sysdate from dual union all
select -1 , 'created' , sysdate - 21 from dual union all
select -1 , 'updated' , sysdate - 21 from dual union all
select 2 , 'deleted' , sysdate from dual
SELECT
tu.person_id,
tu.user_name,
trq.request_status_code,
trq.some_data
FROM
t_user tu,
t_req_data trq
WHERE
tu.person_id = trq.person_id
AND
&in_user = 'ADMIN'
AND request_status_code != 'created'
OR
&in_user != 'ADMIN'
AND &in_user = user_name
Enter value for in_user: 'ADMIN'
old 33: &in_user = 'ADMIN'
new 33: 'ADMIN' = 'ADMIN'
Enter value for in_user: 'ADMIN'
old 38: &in_user != 'ADMIN'
new 38: 'ADMIN' != 'ADMIN'
Enter value for in_user: 'ADMIN'
old 39: AND &in_user = user_name
new 39: AND 'ADMIN' = user_name
PERSON_ID USER_ REQUEST SOME_DATA
1 P1 updated 13-DEC-2011 22:14:32
2 P2 deleted 14-DEC-2011 10:14:32
-1 ADMIN updated 14-DEC-2011 10:14:32
-1 ADMIN updated 23-NOV-2011 10:14:32
2 P2 deleted 14-DEC-2011 10:14:32
SQL> -
Could anyone help me to avoid Cartesian join in this query?
Hi, guys:
Could you help me on this query? I must generate a Cartesian join, but I do not know why it happens. dt.debtorkey, cl.clientkey, inv.invoicekey, ag.agingkey are primary keys of each table. The problem is: I got same tuple for 8 times.
select dt.debtorkey, cl.clientkey, inv.invoicekey, ag.agingkey, dt.DebtorNo, dt.Name as "debtor Name", dt.State, cl.ClientNo, cl.Name as "Client Name", inv.InvNo, inv.PurchOrd, inv.Amt,
to_char(inv.InvDate, 'MM-DD-YY') invoice_date, to_char(ag.DateLastBuy, 'MM-DD-YY') aging_lastbuy, to_char(ag.DateLastPmt, 'MM-DD-YY') aging_lastpmt
from aging ag, invoices inv, debtors dt, clients cl
where ag.clientkey=cl.clientkey
and ag.debtorkey=dt.debtorkey
and inv.clientkey=cl.clientkey
and inv.debtorkey=dt.debtorkey
and ((inv.InvDate>=to_date(:P16_DP_IDF_START_DATE, 'MM/DD/YYYY')
and inv.InvDate<=to_date(:P16_DP_IDF_END_DATE, 'MM/DD/YYYY')
and ag.DateLastBuy=to_date(:P16_DP_IDF_LAST_BUY,'MM/DD/YYYY')
order by dt.name;Thanks a lot!Hi,
Thanks for help. I am sorry for that I do not know how to upload a picture of explain plan. I am struggling to find how to provide sample data. I hope this data format could be at least useful.
"DEBTORKEY","CLIENTKEY","INVOICEKEY","AGINGKEY","DEBTORNO","debtor Name","STATE","CLIENTNO","Client Name","INVNO","PURCHORD","AMT","INVOICE_DATE"
8,2741,744212,276807,"0538","MJN Services, Inc.","UT","2696","Pompano Logistics, LLC","26960590","LK1-17225",1700,"09-25-12"
8,2741,744212,276807,"0538","MJN Services, Inc.","UT","2696","Pompano Logistics, LLC","26960590","LK1-17225",1700,"09-25-12"
8,2741,744212,276807,"0538","MJN Services, Inc.","UT","2696","Pompano Logistics, LLC","26960590","LK1-17225",1700,"09-25-12"
8,2741,744212,276807,"0538","MJN Services, Inc.","UT","2696","Pompano Logistics, LLC","26960590","LK1-17225",1700,"09-25-12"
8,2741,744212,276807,"0538","MJN Services, Inc.","UT","2696","Pompano Logistics, LLC","26960590","LK1-17225",1700,"09-25-12"
8,2741,744212,276807,"0538","MJN Services, Inc.","UT","2696","Pompano Logistics, LLC","26960590","LK1-17225",1700,"09-25-12"
8,2741,744212,276807,"0538","MJN Services, Inc.","UT","2696","Pompano Logistics, LLC","26960590","LK1-17225",1700,"09-25-12"
8,2741,744212,276807,"0538","MJN Services, Inc.","UT","2696","Pompano Logistics, LLC","26960590","LK1-17225",1700,"09-25-12"
8,2741,744213,276807,"0538","MJN Services, Inc.","UT","2696","Pompano Logistics, LLC","26960591","LK1-17241",1700,"09-25-12"
8,2741,744213,276807,"0538","MJN Services, Inc.","UT","2696","Pompano Logistics, LLC","26960591","LK1-17241",1700,"09-25-12"
8,2741,744213,276807,"0538","MJN Services, Inc.","UT","2696","Pompano Logistics, LLC","26960591","LK1-17241",1700,"09-25-12"
8,2741,744213,276807,"0538","MJN Services, Inc.","UT","2696","Pompano Logistics, LLC","26960591","LK1-17241",1700,"09-25-12"
8,2741,744213,276807,"0538","MJN Services, Inc.","UT","2696","Pompano Logistics, LLC","26960591","LK1-17241",1700,"09-25-12"
8,2741,744213,276807,"0538","MJN Services, Inc.","UT","2696","Pompano Logistics, LLC","26960591","LK1-17241",1700,"09-25-12"
8,2741,744213,276807,"0538","MJN Services, Inc.","UT","2696","Pompano Logistics, LLC","26960591","LK1-17241",1700,"09-25-12"
8,2741,744213,276807,"0538","MJN Services, Inc.","UT","2696","Pompano Logistics, LLC","26960591","LK1-17241",1700,"09-25-12"
8,2741,744214,276807,"0538","MJN Services, Inc.","UT","2696","Pompano Logistics, LLC","26960592","LK1-17224",1700,"09-25-12"
8,2741,744214,276807,"0538","MJN Services, Inc.","UT","2696","Pompano Logistics, LLC","26960592","LK1-17224",1700,"09-25-12"
8,2741,744214,276807,"0538","MJN Services, Inc.","UT","2696","Pompano Logistics, LLC","26960592","LK1-17224",1700,"09-25-12"
8,2741,744214,276807,"0538","MJN Services, Inc.","UT","2696","Pompano Logistics, LLC","26960592","LK1-17224",1700,"09-25-12"
8,2741,744214,276807,"0538","MJN Services, Inc.","UT","2696","Pompano Logistics, LLC","26960592","LK1-17224",1700,"09-25-12"
8,2741,744214,276807,"0538","MJN Services, Inc.","UT","2696","Pompano Logistics, LLC","26960592","LK1-17224",1700,"09-25-12"
8,2741,744214,276807,"0538","MJN Services, Inc.","UT","2696","Pompano Logistics, LLC","26960592","LK1-17224",1700,"09-25-12"
8,2741,744214,276807,"0538","MJN Services, Inc.","UT","2696","Pompano Logistics, LLC","26960592","LK1-17224",1700,"09-25-12"I do not know why the tuples with same primary key repeat 8 times.
Edited by: lxiscas on Oct 24, 2012 4:08 PM
Edited by: lxiscas on Oct 24, 2012 4:10 PM -
HI, I have an XMLType column that has the following XML structure:
<Client>
<Report id = "01">
<Item id = "01" Description = ",a.mdfbnelt;yuk" </Item>
<Item id = "02" Description = "AAAAA;yuk" </Item>
<Item id = "03" Description = "XXXXX" </Item>
</Report>
<Report id = "02">
<Item id = "01" Description = ",ABCDEF" </Item>
<Item id = "02" Description = "JHIKLM" </Item>
<Item id = "03" Description = "OPQRST" </Item>
</Report>
</Client>
I would like to extract and insert data into the following file
Table MyTable(Client, Report_id, Item_id, Description)
So I created the following query
SELECT
extractValue(VALUE(x), '/Client/@id')) Client,
extractValue(VALUE(d), '/Report/@id') Report,
extractValue(VALUE(e), '/Item/@id') Description,
extractValue(VALUE(e), '/Item/@Description) Description
FROM XMLDOC2 x,
TABLE(xmlsequence(extract(VALU*E(x), '/Client/Report'))) d,
TABLE(xmlsequence(extract(VALU*E(x), '/Client/Report/Item'))) e
But I get the cartesian product of the reports and the items. I would
like to get the items related to a reports AND the report id on the
same line. If it is not possible, I would like to filter out the items
belonging to report; some kind of where clause.
Anybody has an idea?
regds,
Santhoshkumar.G.-- Xml format
<ITEMLIST>
<ITEM>
<EXTERNALID>ARSH0001</EXTERNALID>
<DESCRIPTION>WHITE DIAGEO SHIRT</DESCRIPTION>
<MATYPE>ZFGM</MATYPE>
<TAXCD>1</TAXCD>
<BRANDID>AR</BRANDID>
<UOMID>PC</UOMID>
<PRODUCTHIERARCHY>METOPSSHFASHN00895</PRODUCTHIERARCHY>
<MANUFACTURER1>FASHION</MANUFACTURER1>
<COLOR>WHITE</COLOR>
<THEME></THEME>
<COLLECTION>empty</COLLECTION>
<FIT></FIT>
<SEASON>S06</SEASON>
<PRDGRP>SH</PRDGRP>
<PRDCOLL>TOPS</PRDCOLL>
<TARGET>ME</TARGET>
<GRID>GRID01</GRID>
<SUBITEM size="38FS" quality="Q2" barcode="100051050" price=" 895.00"></SUBITEM>
<SUBITEM size="38FS" quality="Q3" barcode="100051051" price=" 895.00"></SUBITEM>
<SUBITEM size="39FS" quality="Q2" barcode="100051052" price=" 895.00"></SUBITEM>
<SUBITEM size="39FS" quality="Q3" barcode="100051053" price=" 895.00"></SUBITEM>
<SUBITEM size="40FS" quality="Q2" barcode="100051054" price=" 895.00"></SUBITEM>
<SUBITEM size="40FS" quality="Q3" barcode="100051055" price=" 895.00"></SUBITEM>
<SUBITEM size="42FS" quality="Q2" barcode="100051056" price=" 895.00"></SUBITEM>
<SUBITEM size="42FS" quality="Q3" barcode="100051057" price=" 895.00"></SUBITEM>
<SUBITEM size="44FS" quality="Q2" barcode="100051058" price=" 895.00"></SUBITEM>
<SUBITEM size="44FS" quality="Q3" barcode="100051059" price=" 895.00"></SUBITEM>
<SUBITEM size="46FS" quality="Q2" barcode="100051060" price=" 895.00"></SUBITEM>
<SUBITEM size="46FS" quality="Q3" barcode="100051061" price=" 895.00"></SUBITEM>
<SUBITEM size="48FS" quality="Q2" barcode="100051062" price=" 895.00"></SUBITEM>
<SUBITEM size="48FS" quality="Q3" barcode="100051063" price=" 895.00"></SUBITEM>
<SUBITEM size="39FS" quality="Q1" barcode="8901208428516" price=" 895.00"></SUBITEM><SUBITEM size="40FS" quality="Q1" barcode="8901208428523" price=" 895.00"></SUBITEM><SUBITEM size="42FS" quality="Q1" barcode="8901208428530" price=" 895.00"></SUBITEM><SUBITEM size="44FS" quality="Q1" barcode="8901208428547" price=" 895.00"></SUBITEM><SUBITEM size="46FS" quality="Q1" barcode="8901208428554" price=" 895.00"></SUBITEM><SUBITEM size="48FS" quality="Q1" barcode="8901208428561" price=" 895.00"></SUBITEM><SUBITEM size="38FS" quality="Q1" barcode="8901208428578" price=" 895.00"></SUBITEM></ITEM>
<ITEM>
<EXTERNALID>ARSH0002</EXTERNALID>
<DESCRIPTION>BLACK DIAGEO SHIRT</DESCRIPTION>
<MATYPE>ZFGM</MATYPE>
<TAXCD>1</TAXCD>
<BRANDID>AR</BRANDID>
<UOMID>PC</UOMID>
<PRODUCTHIERARCHY>METOPSSHFASHN00895</PRODUCTHIERARCHY>
<MANUFACTURER1>FASHION</MANUFACTURER1>
<COLOR>BLACK</COLOR>
<THEME></THEME>
<COLLECTION>empty</COLLECTION>
<FIT></FIT>
<SEASON>S06</SEASON>
<PRDGRP>SH</PRDGRP>
<PRDCOLL>TOPS</PRDCOLL>
<TARGET>ME</TARGET>
<GRID>GRID01</GRID>
<SUBITEM size="38FS" quality="Q2" barcode="100051078" price=" 895.00"></SUBITEM>
<SUBITEM size="38FS" quality="Q3" barcode="100051079" price=" 895.00"></SUBITEM>
<SUBITEM size="39FS" quality="Q2" barcode="100051080" price=" 895.00"></SUBITEM>
<SUBITEM size="39FS" quality="Q3" barcode="100051081" price=" 895.00"></SUBITEM>
<SUBITEM size="40FS" quality="Q2" barcode="100051082" price=" 895.00"></SUBITEM>
<SUBITEM size="40FS" quality="Q3" barcode="100051083" price=" 895.00"></SUBITEM>
<SUBITEM size="42FS" quality="Q2" barcode="100051084" price=" 895.00"></SUBITEM>
<SUBITEM size="42FS" quality="Q3" barcode="100051085" price=" 895.00"></SUBITEM>
<SUBITEM size="44FS" quality="Q2" barcode="100051086" price=" 895.00"></SUBITEM>
<SUBITEM size="44FS" quality="Q3" barcode="100051087" price=" 895.00"></SUBITEM>
<SUBITEM size="46FS" quality="Q2" barcode="100051088" price=" 895.00"></SUBITEM>
<SUBITEM size="46FS" quality="Q3" barcode="100051089" price=" 895.00"></SUBITEM>
<SUBITEM size="48FS" quality="Q2" barcode="100051090" price=" 895.00"></SUBITEM>
<SUBITEM size="48FS" quality="Q3" barcode="100051091" price=" 895.00"></SUBITEM>
<SUBITEM size="39FS" quality="Q1" barcode="8901208428653" price=" 895.00"></SUBITEM><SUBITEM size="40FS" quality="Q1" barcode="8901208428660" price=" 895.00"></SUBITEM><SUBITEM size="42FS" quality="Q1" barcode="8901208428677" price=" 895.00"></SUBITEM><SUBITEM size="44FS" quality="Q1" barcode="8901208428684" price=" 895.00"></SUBITEM><SUBITEM size="46FS" quality="Q1" barcode="8901208428691" price=" 895.00"></SUBITEM><SUBITEM size="48FS" quality="Q1" barcode="8901208428707" price=" 895.00"></SUBITEM><SUBITEM size="38FS" quality="Q1" barcode="8901208428714" price=" 895.00"></SUBITEM></ITEM>
</ITEMLIST>
-- Sql
SELECT extract(value(d), '//EXTERNALID/text()').getStringVal() AS EXTERNALID,
extract(value(d), '//DESCRIPTION/text()').getStringVal() AS DESCRIPTION,
extract(value(d), '//MATYPE/text()').getStringVal() AS MATYPE,
extract(value(d), '//TAXCD/text()').getStringVal() AS TAXCD,
extract(value(d), '//BRANDID/text()').getStringVal() AS BRANDID,
extract(value(d), '//UOMID/text()').getStringVal() AS UOMID,
extract(value(d), '//PRODUCTHIERARCHY/text()').getStringVal() AS PRODUCTHIERARCHY,
extract(value(d), '//MANUFACTURER1/text()').getStringVal() AS MANUFACTURER1,
extract(value(d), '//COLOR/text()').getStringVal() AS COLOR,
extract(value(d), '//THEME /text()').getStringVal() AS THEME ,
extract(value(d), '//COLLECTION/text()').getStringVal() AS COLLECTION,
extract(value(d), '//FIT/text()').getStringVal() AS FIT,
extract(value(d), '//SEASON/text()').getStringVal() AS SEASON,
extract(value(d), '//PRDGRP/text()').getStringVal() AS PRDGRP,
extract(value(d), '//PRDCOLL/text()').getStringVal() AS PRDCOLL,
extract(value(d), '//TARGET/text()').getStringVal() AS TARGET,
extract(value(d), '//GRID/text()').getStringVal() AS GRID,
extract(value(z), '//@size').getStringVal() AS size_cd,
extract(value(z), '//@quality').getStringVal() AS quality,
extract(value(z), '//@barcode').getStringVal() AS barcode,
extract(value(z), '//@price').getStringVal() AS price
FROM xml_tab x,
table(xmlsequence(extract(value(x), '//ITEMLIST/ITEM'))) d,
table(xmlsequence(extract(value(x), '//ITEM/SUBITEM')))z
The above sql gives me a cartesian join for all the subitems to the items tag.
i.e.,
externalid
ARSH0001 -- 2 * 12 times for one record.
Pls give me a solution. I am struggling on this.
Please.
Regds,
Santhoshkumar.G. -
Puzzled By Cartesian Join In Query
If I do this query:
SELECT count(*)
FROM
mode_change_history psch
JOIN mode_link psl USING (mode_index)
WHERE
psch.date_changed >= TO_TIMESTAMP ('2008-03-03 05:00:00.000', 'YYYY-MM-DD HH24:MI:SS.FF');
The query takes less than a second and I get the desired results. If I modify the query by adding an additional join to the analysts table, like this:
SELECT count(*)
FROM
mode_change_history psch
JOIN mode_link psl USING (mode_index)
JOIN analysts a USING (analyst_id)
WHERE
psch.date_changed >= TO_TIMESTAMP ('2008-03-03 05:00:00.000', 'YYYY-MM-DD HH24:MI:SS.FF');
The query takes too long (about a minute) and generates a cartesian product(according to the explain plan) when joining the analysts table.
Notes:
I've removed the column names from the SELECT clause and replaced it with a count(*) just to simply this example.
Relevant info on the tables being joined:
mode_change_history columns
mode_index
date_changed
analyst_id
justification
change_type
Primary key on this table: mode_index,date_changed,analyst_id
Approximate rows in table: 50,000
mode_link columns
mode_index
mode_name
parameter_set_id
Primary key on this table is: mode_index
Approximate rows in table: 20,000
analysts columns
analyst_id
user_name
full_name
Primary key on this table is: analyst_id
Approximate rows in table: 500
As you can see, none of the tables have many rows.
After joining the first two tables listed in the query the result of the join would have rows containing mode_index (from mode_change_history and mode_link tables) that satisfy the WHERE clause. This intermediate result set should include the additional column analyst_id from the mode_change_history table. Then I would expect the RDBMS to join the rows from the analysts table that have analyst_id's in the intermediate result set. This does not appear to be happening since I'm seeing the cartesian join line show up in the execution plan.
Any ideas on what's going on?
I would post the explain plans but the Oracle instance is on a network that is not connected to the Internet so I can't easily post any output.
Thank youI don't use them myself. but I did have to debug somebody else's code which was giving all kinds of random results. natural three way join (sounds dirty) - ha!
also, I've seen discrepancies between the manuals for different versions on the syntax and rules. one manual states that the USING clause is only valid for outer joins. another release states that it's good for inner and outer. I've also seen differences regarding the use of the word NATURAL.
the bug it isn't that the optimizer uses a merge join carteian to resolve it (which could still give the correct answer, but possibly not with optimal performance). it's that it screws up the join criteria and returns a cartesian product result set.
my opinion - screw ansi, I'm using oracle syntax. and if some new guy with a t-sql background doesn't like it, tough. I came from a C & Pascal background and had an oracle manual thrown in my lap (it was long enough ago that manuals were still printed, and luckily, being v5, the manuals were small and didn't damage anything). -
Merge cartesian join in query plan
Hi All
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
W are using many GTT's in our code, the query plan have Merge Cartesain join showing cardinality as '1' which is incorrect, as GTT tables have many rows. Due to this query is taking ages to execute.
I am trying to sue dynamic sampling, but it doesn't seem to work.
please help on this.user8650395 wrote:
Hi All
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
W are using many GTT's in our code, the query plan have Merge Cartesain join showing cardinality as '1' which is incorrect, as GTT tables have many rows. Due to this query is taking ages to execute.
I am trying to sue dynamic sampling, but it doesn't seem to work.
please help on this.Interesting.
There was a a thread a day or two ago about when dynamic sampling does not work. You can search OTN for it if you like. Also check the docs to make sure that dynamic sampling works with GTTS
One problem with GTTS is getting accurate statistics. Have you considered using DBMS_STATISTICS to set the statistics on the table to adjust the cardinality?
Your cardinality of 1 sounds incorrect. In theory a cartesian join against one row should be painelss; unfortunately your cardinality figure seems to be off! Sometimes in cases like yours the cost-based optimizer will choose a Cartesian join even when the table joins are properly specified. -
Cartesian Join query optimization
Hello Experts!
I have a question about cartesian join query which might look a bit weird.
Assume the SQL query like that:
SELECT DISTINCT A.NAME
FROM A, B, C;
Here we have cartesian join for 3 tables A, B and C.
It looks to me, in order to get the result for such a particular SQL tables/sets B and C need to be accessed only to ensure they return at least 1 row (otherwise result set is empty), query table A, but there is no actual need to join the data.
If you run such a query Oracle is doing full table scans and actually joins the data.
Yes, DBMS is doing exactly what you are asking for, but I wonder if there is any way (SQL hint or db parameter or anything else) to enforce more optimal access path here?
Obvious solution to remove B and C tables from the SELECT statement is not acceptable. :-)
Thank you!Your statement in the other thread indicates you don't understand how the BI prompts actually work because you say you want it to do something that doesn't make sense for it to do.
Of course Product and Account levels will be constrained to the interval you specified. It wouldn't make sense for them not to be. Because that would mean returning data for based on product and account levels that has a different open data range than what you specified.
All UI prompt dialogs I have seen use AND relationships between the parameters. If there are three parameters (A, B, C) then the ultimate relationship is 'A AND B AND C'; not 'A OR (B AND C)', 'A AND (B OR C)', 'A OR (B OR C).
Unless the tool allows you to select OR relationships you need to use a separate dialog box (parameter dialog) for each condition set.:-)
I understand how BI prompts work and basically agree on your comment, but there are two problems here:
1. I need to convince the customer his original requirements are not valid. Customer want it to work different way and there are some reasons why.
2. There are pretty large dimensions and fact tables used here, so when I choose filter criteria for the Product (which is small table) to populate/recalculate prompt values, large SR dimension and fact tables are joined too, and if there are Account dimension filters added, huge Account dimension will be added as well. This looks to be a bit sub-optimal for just populating the Product prompt values.
Of course, technically this is solvable, but requires to put some extra effort and does not solve the 1st issue.
That other link doesn't explain the sample code you posted in this thread. Post the actual query that is being generated and the query that you want to actually use.This is what is generated:
>
select distinct T311691.X_CUST_SUBTYPE as c1
from
WC_LOV_SR_AREA_H T311695,
WC_LOV_PROD_H T311687,
WC_LOV_CUST_TYPE_H T311691,
W_SRVREQ_D T302384 /* Dim_W_SRVREQ_D */
where ( T311687.LEV1 = 'Product X' and T311691.X_CUST_TYPE = 'Business' and T302384.OPEN_DT between TO_DATE('2012-03-01 00:00:00' , 'YYYY-MM-DD HH24:MI:SS') and TO_DATE('2012-03-31 00:00:00' , 'YYYY-MM-DD HH24:MI:SS') )
order by c1
>
This is what is actually needed to query this data:
>
select distinct T311691.X_CUST_SUBTYPE as c1
from
WC_LOV_CUST_TYPE_H T311691
where ( T311691.X_CUST_TYPE = 'Business' )
order by c1 -
How to join 2 tables with unequal rows without resulting in a cartesian join
Hello,
This is the first time I have ever posted in any forum so please tell me if I should be doing this better.
Basically I have 2 tables with an unequal number of rows. For demonstration purposes, assume these are my 2 tables:
Table 1:
BaseKey
Letters
A
A
A
B
A
C
B
A
B
B
Table 2:
BaseKey
Numbers
A
1
A
2
B
1
B
2
B
3
I need to join them so that the data would appear like this
BaseKey
Letters
Numbers
A
A
1
A
B
2
A
C
null
B
A
1
B
B
2
B
null
3
Does anyone have any ideas how to do this using T-SQL without creating a cartesian join of 12 rows?
Thanks.>> This is the first time I have ever posted in any forum so please tell me if I should be doing this better. <<
Please post DDL, so that people do not have to guess what the keys, constraints, Declarative Referential Integrity, data types, etc. in your schema are. Learn to follow ISO-11179 data element naming conventions and formatting rules. Temporal data should
use ISO-8601 formats. Code should be in Standard SQL as much as possible and not local dialect.
This is minimal polite behavior on SQL forums. What you did post is useless! Can you program from it? Neither can we. And we have to do all the extra typing for you.
CREATE TABLE Foo
(base_something CHAR(1) NOT NULL,
something_letter CHAR(1) NOT NULL,
PRIMARY KEY (base_something, something_letter));
INSERT INTO Foo
VALUES ('A', 'A'),
('A', 'B'),
('A', 'C'),
('B', 'A'),
('B', 'B');
CREATE TABLE Bar
(CHAR(1) NOT NULL,
something_digit CHAR(1) NOT NULL,
PRIMARY KEY (base_something, something_digit));
INSERT INTO Foo
VALUES ('A', '1'),
('A', '2'),
('B', '1'),
('B', '2'),
('B', '3');
>> I need to join them so that the data would appear like this
base_something Letters Numbers <<
This looks like you are taking two decks of punch cards and merging them together, without any logical rules, just physical position in their decks relative to the base_something groups.
WITH Foo_Deck
AS
(SELECT base_something, something_letter,
ROW_NUMBER()
OVER (PARTITION BY base_something
ORDER BY something_letter) AS card),
Bar_Deck
AS
(SELECT base_something, something_digit,
ROW_NUMBER()
OVER (PARTITION BY base_something
ORDER BY something_digit) AS card),
SELECT F.base_something, F.something_digit, B.something_letter
FROM Foo_Deck AS F
LEFT OUTER JOIN
Bar_Deck AS B
ON B.base_something = F.base_something
AND B.card = F.card;
--CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
in Sets / Trees and Hierarchies in SQL -
Outer/Cartesian Join using same table
Hi All,
I'm needing to write a query, which is kind of like an outer join/cartesian join that essentially tags each customer in my database with a flag indicating whether they have received a particular product for a given year. There are 8 products so for each distinct customer_id in my database I want 8 records, with a 'Yes' or 'No' indicating whether they have received this product or not. Currently, for a given year, if a customer only receives 2 out of the 8 products there will be two records for that individual but I want 8 records for each individual so that each product is shown to either have been received or not received by the customer. This is the table format I'm looking for:
CUSTOMER_ID PRODUCT_CD PRODUCT_RECEIVED_FLAG YEAR
999999999 1 Y 2010
999999999 2 N 2010
999999999 3 N 2010
999999999 4 N 2010
999999999 5 N 2010
999999999 6 N 2010
999999999 7 Y 2010
999999999 8 Y 2010
888888888 1 N 2010
888888888 2 N 2010
888888888 3 Y 2010
888888888 4 Y 2010
888888888 5 N 2010
888888888 6 N 2010
888888888 7 Y 2010
888888888 8 Y 2010
777777777 1 Y 2010
777777777 2 Y 2010
777777777 3 Y 2010
777777777 4 Y 2010
777777777 5 Y 2010
777777777 6 Y 2010
777777777 7 N 2010
777777777 8 N 2010Thanks,
EdI am in good mood today ;) :
with customer as (
select '999999999' customer_id from dual union all
select '888888888' from dual union all
select '777777777' from dual
product as (
select level product_cd from dual connect by level <= 8
orders as (
select '999999999' customer_id,1 product_cd,2010 year from dual union all
select '999999999',7,2010 from dual union all
select '999999999',8,2010 from dual union all
select '888888888',3,2010 from dual union all
select '888888888',4,2010 from dual union all
select '888888888',7,2010 from dual union all
select '888888888',8,2010 from dual union all
select '777777777',1,2010 from dual union all
select '777777777',2,2010 from dual union all
select '777777777',3,2010 from dual union all
select '777777777',4,2010 from dual union all
select '777777777',5,2010 from dual union all
select '777777777',6,2010 from dual union all
select '777777777',7,2010 from dual union all
select '777777777',8,2010 from dual
-- end of on-the-fly data sample
select c.customer_id,
p.product_cd,
nvl2(o.product_cd,'Y','N') product_received_flag,
y.year
from customer c
cross join
product p
cross join
select distinct year
from orders
) y
left join
orders o
on (
c.customer_id = o.customer_id
and
p.product_cd = o.product_cd
and
y.year = o.year
order by y.year,
c.customer_id desc,
p.product_cd
CUSTOMER_ PRODUCT_CD P YEAR
999999999 1 Y 2010
999999999 2 N 2010
999999999 3 N 2010
999999999 4 N 2010
999999999 5 N 2010
999999999 6 N 2010
999999999 7 Y 2010
999999999 8 Y 2010
888888888 1 N 2010
888888888 2 N 2010
888888888 3 Y 2010
CUSTOMER_ PRODUCT_CD P YEAR
888888888 4 Y 2010
888888888 5 N 2010
888888888 6 N 2010
888888888 7 Y 2010
888888888 8 Y 2010
777777777 1 Y 2010
777777777 2 Y 2010
777777777 3 Y 2010
777777777 4 Y 2010
777777777 5 Y 2010
777777777 6 Y 2010
CUSTOMER_ PRODUCT_CD P YEAR
777777777 7 Y 2010
777777777 8 Y 2010
24 rows selected.
SQL> SY.
P.S. Code assumes at least one customer ordered at least one product within each year. Otherwise you will need year table.
Edited by: Solomon Yakobson on Oct 28, 2011 2:36 PM -
Hi,
I'm having this plan, But I'm not able to understand as to which table/view it's producing the MERGE CARTESIAN JOIN, and BUFFER SORT, is it from CM_PAY_TRANS_VW but then which column it's referring to?
Please advice
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 1 | 249 | 24 (13)| 00:00:01 |
|* 1 | HASH JOIN | | 1 | 249 | 24 (13)| 00:00:01 |
| 2 | VIEW | CM_PAY_TRANS_VW | 1 | 160 | 12 (9)| 00:00:01 |
| 3 | HASH GROUP BY | | 1 | 179 | 12 (9)| 00:00:01 |
| 4 | NESTED LOOPS OUTER | | 1 | 179 | 11 (0)| 00:00:01 |
| 5 | NESTED LOOPS | | 1 | 149 | 10 (0)| 00:00:01 |
| 6 | MERGE JOIN CARTESIAN | | 19 | 2242 | 9 (0)| 00:00:01 |
| 7 | TABLE ACCESS BY INDEX ROWID | CI_PAY_SEG | 1 | 28 | 1 (0)| 00:00:01 |
| 8 | NESTED LOOPS | | 1 | 78 | 2 (0)| 00:00:01 |
| 9 | TABLE ACCESS BY INDEX ROWID| CI_PAY | 1 | 50 | 1 (0)| 00:00:01 |
|* 10 | INDEX RANGE SCAN | XT156S2 | 1 | | 1 (0)| 00:00:01 |
|* 11 | INDEX RANGE SCAN | XT165S1 | 3 | | 1 (0)| 00:00:01 |
| 12 | BUFFER SORT | | 30 | 1200 | 8 (0)| 00:00:01 |
|* 13 | TABLE ACCESS FULL | CI_SA_TYPE_L | 30 | 1200 | 7 (0)| 00:00:01 |
|* 14 | TABLE ACCESS BY INDEX ROWID | CI_SA | 1 | 31 | 1 (0)| 00:00:01 |
|* 15 | INDEX UNIQUE SCAN | XM199P0 | 1 | | 1 (0)| 00:00:01 |
| 16 | TABLE ACCESS BY INDEX ROWID | CI_PAY_CAN_RSN_L | 1 | 30 | 1 (0)| 00:00:01 |
|* 17 | INDEX UNIQUE SCAN | XC557P0 | 1 | | 1 (0)| 00:00:01 |
| 18 | VIEW | CM_PAY_TNDR_TYPES_VW | 174 | 15486 | 11 (10)| 00:00:01 |
| 19 | HASH GROUP BY | | 174 | 15660 | 11 (10)| 00:00:01 |
| 20 | NESTED LOOPS OUTER | | 174 | 15660 | 10 (0)| 00:00:01 |
| 21 | NESTED LOOPS OUTER | | 160 | 10080 | 9 (0)| 00:00:01 |
| 22 | TABLE ACCESS FULL | CI_PAY_EVENT | 160 | 4640 | 7 (0)| 00:00:01 |
| 23 | TABLE ACCESS BY INDEX ROWID | CI_PAY_TNDR | 1 | 34 | 1 (0)| 00:00:01 |
|* 24 | INDEX RANGE SCAN | XT265S3 | 1 | | 1 (0)| 00:00:01 |
| 25 | TABLE ACCESS BY INDEX ROWID | CI_TENDER_TYPE_L | 1 | 27 | 1 (0)| 00:00:01 |
|* 26 | INDEX UNIQUE SCAN | XC583P0 | 1 | | 1 (0)| 00:00:01 |
Predicate Information (identified by operation id):
1 - access("A"."PAY_EVENT_ID"="B"."PAY_EVENT_ID")
10 - access("P"."PAY_EVENT_ID"='010253513440')
11 - access("P"."PAY_ID"="PSEG"."PAY_ID")
13 - filter("SA_TYP"."LANGUAGE_CD"='ENG')
14 - filter("SA"."SA_TYPE_CD"="SA_TYP"."SA_TYPE_CD")
15 - access("PSEG"."SA_ID"="SA"."SA_ID")
17 - access("P"."CAN_RSN_CD"="RSN"."CAN_RSN_CD"(+) AND "RSN"."LANGUAGE_CD"(+)='ENG')
24 - access("EVT"."PAY_EVENT_ID"="TDR"."PAY_EVENT_ID"(+))
26 - access("TDR"."TENDER_TYPE_CD"="TT"."TENDER_TYPE_CD"(+) AND "TT"."LANGUAGE_CD"(+)='ENG')is it CM_PAY_TRANS_VWYou know your data model, we don't. You also haven't posted the query, so it's a bit difficult to tell but it looks to me as though it's CI_SA_TYPE_L which is responsible. FULL TABLE ACCESS with a filter rather than an access predicate.
As to why this happening, you might find this article by Jonathan Lewis sheds some light.
Cheers, APC
Blog : http://radiofreetooting.blogspot.com/ -
CacheSplitMemoryReader - Cartesian join?
Hi,
We have a process where we run multiple matches on the input file, and then group number from each match is sent to a query transform to do an outer join before it is sent to associative match transform.
The process runs fine with small data set, but when we ran it for a production size file, the process ran for about 15 hours.
Looking at the monitor logs, we see a very large number against "CacheSplitMemoryReader".
While testing it with small set (say, 11 records in the input file), I see "121" rowcount against "CacheSplitMemoryReader".
Though I am not sure what "CacheSplitMemoryReader" means, my guess is that it is related to the join. And for some reason, while joining all the four input streams, DS decides to do a Cartesian join?
Though, the output is fine - with 11 records coming out of associative match.
We have tried changing outer join order in the query transform to see if that makes any difference. But so far, everytime it ends up with 121 records for "CacheSplitMemoryReader".
Any insight into what is happening and how to avoid it?
Thanks,
Gaurav
Edit: This is for DataService 12.2.0.1
Edited by: Gaurav Pandit on Nov 4, 2009 2:53 PMHello Gaurav,
I am curious why you are doing this join at all.
If you are trying to optimize the peformance of Associate, I recommend bypassing the rows that have no group number. In other words Associate should receive only the rows that have at least one group number populated. And then you will have to Merge back the rows.
I also recommend referring our bluprints posted here SAP Data Services Blueprints for example usage of Match and Associate. Please take a look at jobs named *_MatchAssociative. Here you will see how specific rows are bypassed and merged back for different Match transform. Similar principle can be applied for Associate. The Case condition will be based on Group Numbers.
Thanks,
Abhiram -
I am creating a view, but the explain plan is telling me that I have a cartesian join. I can not seem to identify it. Can some help me here please. Here is the SQL:
CREATE OR REPLACE VIEW VW_SERVICE_HEADER
SERVICE_ID,
JON,
SERVICE_ACTION,
PROGRAM
AS
SELECT SH.SERVICE_ID,
SH.JON.JULIAN||
SH.JON.SHOP_CODE||
SH.JON.ORG_CODE||
SH.JON.JON_SEQUENCE JON,
SH.JON_ACTION SERVICE_ACTION,
P.PROGRAM_NAME
FROM ITM.TB_ITEM_MASTER IM, FLD.TB_SERVICE_DETAIL SD,
FLD.TB_SERVICE_HEADER SH, LKP.TB_STAGE S, LKP.TB_PROGRAM P,
TABLE(IM.PROGRAMS) IMP
WHERE
S.STAGE_ID (+) = SH.STAGE_ID AND
IM.ITEM_NO_ID (+) = SH.COMPONENT_REPAIR_ID AND
SH.SERVICE_ID = SD.SERVICE_ID (+) AND
P.PROGRAM_ID (+) = IMP.PROGRAM_ID AND
(P.PROGRAM_ID = SYS_CONTEXT('CTX_DMIS_PROGRAMS','PROGRAM_ID') OR SYS_CONTEXT('CTX_DMIS_PROGRAMS', 'PROGRAM_ID') IS NULL)
ORDER BY SH.SERVICE_ID DESC
/how about this. Will this work???
CREATE OR REPLACE VIEW DMIS_DATA.VW_SERVICE_HEADER_TEST
SERVICE_ID,
JON,
SERVICE_ACTION,
ORGANIZATION_NAME,
PROGRAM
AS
SELECT SH.SERVICE_ID,
SH.JON.JULIAN||
SH.JON.SHOP_CODE||
SH.JON.ORG_CODE||
SH.JON.JON_SEQUENCE JON,
SH.JON_ACTION SERVICE_ACTION,
O.ORGANIZATION_NAME,
P.PROGRAM_NAME
FROM ITM.TB_ITEM_MASTER IM,
FLD.TB_SERVICE_DETAIL SD,
FLD.TB_SERVICE_HEADER SH,
LKP.TB_STAGE S,
LKP.TB_PROGRAM P,
FLD.TB_ORGANIZATION O,
TABLE(IM.PROGRAMS) IMP
WHERE
S.STAGE_ID (+) = SH.STAGE_ID AND
IM.ITEM_NO_ID (+) = SH.COMPONENT_REPAIR_ID AND
SH.SERVICE_ID = SD.SERVICE_ID (+) AND
P.PROGRAM_ID (+) = IMP.PROGRAM_ID AND
O.ORG_ID(+) = SH.JON.ORG_CODE AND
(P.PROGRAM_ID = SYS_CONTEXT('CTX_DMIS_PROGRAMS','PROGRAM_ID')
OR SYS_CONTEXT('CTX_DMIS_PROGRAMS', 'PROGRAM_ID') IS NULL)
ORDER BY SH.SERVICE_ID DESC
I added another table O that could help link IMP and P to the rest -
Expecting a cartesian join but did not get 1 (try to understand what is hap
Hello Oracle XML DB gurus,
I have successfully registered my schemas and inserted about 10,000 XML documents into the repository. Now I need to start reporting on the data that is in the documents. Following is a simplified form of my set-up.
I have a table that contain a XML_TYPE column that is schema based.
I will call the table TEST_REF it has two columns: ID number (PK) and XML_DOC which is of the foo schema.
foo schema has the following structure (foo is unbounded).
<DataSet>
<fooList>
<foo>
<val1></val1>
<val2></val2>
</foo>
<foo>
<val1></val1>
<val2></val2>
</foo>
</fooList>
</DataSet>
What I would like to do is select the XML document that I want to extract data from using the ID column. After that I wanted to be able to select all of the data values in /DataSet/fooList/foo from that document (val1 & val2).
I was able to do just that using the following query. However, I do not understand why the following query does not give me a cartesian product when I try to operate on mulitple documents. I'm actually getting exactly what I want, which are the individual data values from each document. I just need to understand what is going on. Does the table() function when used in this fashion perform a inner join for you? I hope this make sense.
select doc.id, extractvalue(Column_value,'/foo/val1') as VALUE1,
extractvalue(Column_value,'/foo/val2') as VALUE2
from test_ref doc,
table(XMLSequence(extract(doc.XML_DOC,'/DataSet/fooList/foo'))) foobar
where doc.id ='1'
------------------------ second where causes the I thought would cause a cartesian join--------------------
where doc.id in (1,2)
Sample data and results when using second where clause:
ID=1
<DataSet>
<fooList>
<foo>
<val1>2</val1>
<val2>22</val2>
</foo>
<foo>
<val1>4</val1>
<val2>44</val2>
</foo>
</fooList>
</DataSet>
ID=2
<DataSet>
<fooList>
<foo>
<val1>1</val1>
<val2>11</val2>
</foo>
<foo>
<val1>3</val1>
<val2>33</val2>
</foo>
</fooList>
</DataSet>
Results:
ID Value1 Value2
1 2 22
1 4 44
2 1 11
2 3 33
If what I'm asking does not make sense please let me know. I'm a newbe with this Oracle XML DB stuff. However, I really like what I have seen so far!
Thanks in advance
DerrickIt's a correlated join...
-
Hi ,
Can any body has any ideas what is disadvantage of Cartesion Merge Join ?
If i will remove it it will give me any performance benifie?If you are wondering how to make a query more efficient then you'd be better off posting the data mentioned here: [When your query takes too long...|http://forums.oracle.com/forums/thread.jspa?messageID=3299435]
As far as the Cartesian Merge Join, I would say that if it is processing a lot of data then it would be 'bad.' However, if it is dealing with a small set of rows then it may not be a 'bad' thing either. The answer is always 'it depends.'
Maybe you are looking for
-
How do I copy over files from "Previous System 1" to my current system
Hello. I was having trouble with starting up my computer. I used a friend's computer to check Apple's Knowledge Base. The suggestion was to perform an Arhive and Install and to select the option of preserving my user and network settings. I could not
-
What is the problem with business catalyst?
Once in every one hundred attempts the business catalyst website will actually let me upload my site, if the service is not going to work let me know so I can find someone to host my site.
-
Bugs on Update Retriever 2.14 - Cannot get update information correctly
After clean install update retriever 2.14 (updateretriever214-2008-5-13.exe) in clear install Thinkpad R51, In get new update, after select machine type, operating system, language, and get search for updates for 1st time and successfully download up
-
Can receive e-mail but can't send
This is an Ipad 4, Had an Ipad1before and everything worked good..
-
Zenwork 7.3 doesn't finish to install error writing...
Hi We are triyng to install a Zen for desktops 7 update 3 into a netware 6.5 sp7 the install process at the end takes an eternity, an we got allways an error telling about to lose the connection to the server or we have no rigths to write the file ze