Converting oracle join to Ansi sql join
Hi Guys,
I am new to SQL and trying to convert the following Oracle query (joins) into ANSI sql joins...Can someone please help me?
SELECT M.EXTERNALCODE, M.NAME AS MNAME, SC.BIRIM, SM.TRANSACTIONDATE, SMD.AMOUNT,
SMD.UNITPRICE, SM.ID AS SMID, SMD.ID AS SMDID, F.NAME AS FNAME,
IFNULL (SMD.AMOUNT, 0, SMD.AMOUNT) * IFNULL (SMD.UNITPRICE, 0, SMD.UNITPRICE) AS TOTALPRICE, SMD.AMOUNT AS RECEIVED_QUANTITY,
PD.ORDERID, PD.AMOUNT QUANTITY, PO.PROCESSDATE
FROM STOCKMAINTRANSACTION SM,
STOCKMAINTRANSACTIONDETAIL SMD,
MATERIAL M,
STOCKCARD SC,
FVSTOCK FVS,
FIRM F,
PURCHASEORDER PO,
PURCHASEORDERDETAIL PD,
PURCHASEORDERDETAILSUPPLIED PDS
WHERE SM.ID = SMD.MAINTRANSACTIONID
AND SMD.MATERIALID = M.ID
AND SMD.STOCKCARDID = SC.ID
AND SM.PROPREF = FVS.RECORDID(+)
AND FVS.FIELDID(+) = 2559
AND FVS.FLEVEL(+) = 'F'
AND F.ID(+) = SUBSTR (FVS.FVALUE, 1, 9)
AND SM.TRANSDEFID in (999,2329,2344,2370,150000903,150005362)
AND SMD.CANCELLED = 0
AND SMD.STOCKUPDATED = 1
AND SMD.ID = PDS.STOCKMAINTRANSACTIONDETAILID
AND PDS.ORDERDETAILID = PD.ORDERDETAILID
AND PO.ORDERID = PD.ORDERID
AND (M.ID = {@MATERIALID@} OR {@MATERIALID@} = 0)
AND (SM.STOREID = {@STOREID@} OR {@STOREID@} = 0)
AND (F.ID = {@SUPPLIERID@} OR {@SUPPLIERID@} = 0)
AND SM.TRANSACTIONDATE BETWEEN {@STARTDATE@} AND {@ENDDATE@}
ORDER BY F.NAME, M.EXTERNALCODE, SM.TRANSACTIONDATE
Really appreciate the help!
Thanks.
Hi,
Welcome to the forum!
To convert to ANSI syntax, replace join conditions in the WHERE clause
FROM x
, y
WHERE x.x1 = y.y1
AND x.x2 = y.y2with ON conditions in the FROM clause:
FROM x
JOIN y ON x.x1 = y.y1
AND x.x2 = y.y2In inner joins, conditions that do not reference 2 tables are not really join conditions, so it doesn't matter if they are in the FROM clause or in the WHERE clause.
In your case
SM.TRANSDEFID in (999,2329,2344,2370,150000903,150005362)could be part of a join condition involving sm, or it could be in the WHERE clause. Most people find it clearer if 1-table conditions like this are in the WHERE clause.
Again, this only applies to inner joins. For outer joins, all conditions that apply to a table that may lack matching rows must be included in the FROM clause, like this:
LEFT OUTER JOIN fvstock fvs ON sm.propref = fvs.recordid
AND fvs.fieldid = 2559
AND fvs.flevel = 'F'Try it.
If you have trouble, post your best attempt, along with CREATE TABLE and INSERT statements for a little sample data from all the tables involved, and the results you want from that data. Simplify the problem. Post only the tables and columns that you don't know how to handle.
See the forum FAQ {message:id=9360002}
user8428528 wrote:
AND (M.ID = {@MATERIALID@} OR {@MATERIALID@} = 0)
AND (SM.STOREID = {@STOREID@} OR {@STOREID@} = 0)
AND (F.ID = {@SUPPLIERID@} OR {@SUPPLIERID@} = 0)
AND SM.TRANSACTIONDATE BETWEEN {@STARTDATE@} AND {@ENDDATE@}This is not valid Oracle SQL. Is {@MATERIALID@} some kind of variable?
Similar Messages
-
OWB 10.2.0.4 ANSI SQL join problem
Hi
Its seams to me, that in OWB 10.2.0.4 there is something broken with ANSI SQL joins and instead of ANSI joins there is used oracle SQL joins only. Maybe someone can point some solutions? I can’t rewrite all mappings with union and other operators. And manually pl/sql editing also would be big problem."Am I correct in assuming you did not code ANSI joins?" -> yes, i am coding Oracle SQL joins and with this option just generating ANSI joins.
With ANSI SQL join you can use OR and IN operands (and code looks more readable).
It is question of performance (so for example 80% of dataset you can join by one column other 15% by second etc ..). So this all can be rewritten also in Split->join->union all, but if you have several such joins, this will be painfully. -
Hi
How to use ANSI SQL JOINS (9i) for below query
SELECT EMP.EMPNO,EMP_T.TNO,EMP_T.SAL1 FROM EMP,EMP_T WHERE EMP.EMPNO=EMP_T.TNO
UNION ALL
SELECT EMP.EMPNO,EMP_T.TNO,EMP_T.SAL2 FROM EMP,EMP_T WHERE EMP.EMPNO=EMP_T.TNO
UNION ALL
SELECT EMP.EMPNO,EMP_T.TNO,EMP_T.SAL3 FROM EMP,EMP_T WHERE EMP.EMPNO=EMP_T.TNO
EMPNO TNO SAL1
7369 7369 100
7499 7499 1000
7566 7566 400
7782 7782 4000
7369 7369 200
7499 7499 2000
7566 7566 500
7782 7782 5000
7369 7369 300
7499 7499 3000
7566 7566 600
EMPNO TNO SAL1
7782 7782 6000
Regards
MMSELECT EMP.EMPNO,
EMP_T.TNO,
EMP_T.SAL1
FROM EMP
JOIN EMP_T ON ( EMP.EMPNO = EMP_T.TNO )
UNION ALL
SELECT EMP.EMPNO,
EMP_T.TNO,
EMP_T.SAL2
FROM EMP
JOIN EMP_T ON ( EMP.EMPNO = EMP_T.TNO )
UNION ALL
SELECT EMP.EMPNO,
EMP_T.TNO,
EMP_T.SAL3
FROM EMP
JOIN EMP_T ON ( EMP.EMPNO = EMP_T.TNO ) -
Configure "Query Builder" for Theta-Style Joins over ANSI-Style Joins
Can SQL Developer be configured to auto generate theta-style joins instead of ANSI-style joins when building queries? This happens when I generate a query using the Query Builder and then switch over to the Worksheet tab to see the SQL code.
Sample code:
Theta-style join syntax uses commas to separate multiple table names and creates the joins in the Where clause:
SELECT c.name
FROM instructors i, courses c
WHERE i.firstname = 'Mary' AND i.lastname = 'Williams'
AND i.course_id = c.course_id;
ANSI syntax uses the JOIN and ON keywords instead:
SELECT c.name
FROM instructors i JOIN courses c
ON i.course_id = c.course_id
WHERE i.firstname = 'Mary' AND i.lastname = 'Williams';Hi Wes,
There is no preference for configuring this that I know of, but Query Builder is fairly clever about detecting your flavor of SQL from the worksheet then sticking with it. If you design it graphically, the default flavor is ANSI, but QB seems to respect any worksheet edits that switch it to another flavor. I wouldn't vouch for that absolutely, but perhaps it's behavior you can take advantage of.
Regards,
Gary
SQL Developer Team -
Need help converting Oracle PIVOT script to SQL Server
I hope it is not inappropriate to ask for SQL Server question in a .NET forum. I can not understand SQl 2k5+ syntax for pivoting. I am pivoting on company name and storenbr in the following. Thanks for any help.
WITH dummydata AS
SELECT 'Store1' AS storenbr, 2 AS period, 1 AS weeknbr, '40' AS PLU, 'tomato' as descrip, 16 AS used, 100 AS wasted from dual UNION ALL
SELECT 'Store1' AS storenbr, 2 AS period, 1 AS weeknbr, '50' AS PLU, 'bacon' as descrip, 87 AS used, 100 AS wasted from dual UNION ALL
SELECT 'Store1' AS storenbr, 2 AS period, 2 AS weeknbr, '40' AS PLU, 'tomato' as descrip, 26 AS used, 100 AS wasted from dual UNION ALL
SELECT 'Store1' AS storenbr, 2 AS period, 2 AS weeknbr, '50' AS PLU, 'bacon' as descrip, 97 AS used, 100 AS wasted from dual UNION ALL
SELECT 'Store2' AS storenbr, 2 AS period, 1 AS weeknbr, '40' AS PLU, 'tomato' as descrip, 16 AS used, 100 AS wasted from dual UNION ALL
SELECT 'Store2' AS storenbr, 2 AS period, 1 AS weeknbr, '50' AS PLU, 'bacon' as descrip, 87 AS used, 100 AS wasted from dual UNION ALL
SELECT 'Store2' AS storenbr, 2 AS period, 2 AS weeknbr, '40' AS PLU, 'tomato' as descrip, 26 AS used, 100 AS wasted from dual UNION ALL
SELECT 'Store2' AS storenbr, 2 AS period, 2 AS weeknbr, '50' AS PLU, 'bacon' as descrip, 97 AS used, 100 AS wasted from dual UNION ALL
SELECT 'Store3' AS storenbr, 2 AS period, 1 AS weeknbr, '40' AS PLU, 'tomato' as descrip, 18 AS used, 100 AS wasted from dual UNION ALL
SELECT 'Store3' AS storenbr, 2 AS period, 1 AS weeknbr, '50' AS PLU, 'bacon' as descrip, 89 AS used, 100 AS wasted from dual UNION ALL
SELECT 'Store3' AS storenbr, 2 AS period, 2 AS weeknbr, '40' AS PLU, 'tomato' as descrip, 28 AS used, 100 AS wasted from dual UNION ALL
SELECT 'Store3' AS storenbr, 2 AS period, 2 AS weeknbr, '50' AS PLU, 'bacon' as descrip, 99 AS used, 100 AS wasted from dual
, store_details as
SELECT 'Store3' AS storenbr, 'D-Bingham' as districtname, 'R-15 James' as regionname, 'C-Atlantic' as companyname from dual UNION ALL
SELECT 'Store2' AS storenbr, 'D-Dunley' as districtname, 'R-15 James' as regionname, 'C-Atlantic' as companyname from dual UNION ALL
SELECT 'Store1' AS storenbr, 'D-Murdoc' as districtname, 'R-16 Reynolds' as regionname, 'C-Soutn' as companyname from dual
, pivoted as
select storenbr
, plu
, max(descrip) as Descrip
, max(decode(dd.weeknbr, 1, used , 0)) as Week1used
, max(decode(dd.weeknbr, 1, wasted , 0)) as Week1wasted
, max(decode(dd.weeknbr, 2, used , 0)) as Week2used
, max(decode(dd.weeknbr, 2, wasted , 0)) as Week2wasted
, max(decode(dd.weeknbr, 3, used , 0)) as Week3used
, max(decode(dd.weeknbr, 3, wasted , 0)) as Week3wasted
, max(decode(dd.weeknbr, 4, used , 0)) as Week4used
, max(decode(dd.weeknbr, 4, wasted , 0)) as Week4wasted
, max(decode(dd.weeknbr, 5, used , 0)) as Week5used
, max(decode(dd.weeknbr, 5, wasted , 0)) as Week5wasted
from dummydata dd
group by storenbr, plu
order by storenbr, plu
select decode(grouping(stores.storenbr), 0, stores.storenbr, decode(grouping(districtname), 0, districtname, decode(grouping(regionname), 0, regionname, decode(grouping(companyname), 0, companyname, 'GRAND')))) as storenbr
, decode(grouping(descrip), 0, descrip, 'TOTAL') as descrip
--== I substited Description for clarity
, sum(Week1used) as Week1used
, sum(Week1wasted) as Week1wasted
, sum(Week2used) as Week2used
, sum(Week2wasted) as Week2wasted
, sum(Week3used) as Week3used
, sum(Week3wasted) as Week3wasted
, sum(Week4used) as Week4used
, sum(Week4wasted) as Week4wasted
, sum(Week5used) as Week5used
, sum(Week5wasted) as Week5wasted
, companyname
from pivoted pvt
inner join store_details stores on pvt.storenbr = stores.storenbr
group by companyname
, rollup ( regionname
, districtname
, stores.storenbr
, descrip
;New output:
STORENBR DESCRIP WEEK1USED WEEK1WASTED WEEK2USED WEEK2WASTED WEEK3USED WEEK3WASTED WEEK4USED WEEK4WASTED WEEK5USED WEEK5WASTED COMPANYNAME
Store1 bacon 87 100 97 100 0 0 0 0 0 0 C-Soutn
Store1 tomato 16 100 26 100 0 0 0 0 0 0 C-Soutn
Store1 TOTAL 103 200 123 200 0 0 0 0 0 0 C-Soutn
D-Murdoc TOTAL 103 200 123 200 0 0 0 0 0 0 C-Soutn
R-16 Reynolds TOTAL 103 200 123 200 0 0 0 0 0 0 C-Soutn
C-Soutn TOTAL 103 200 123 200 0 0 0 0 0 0 C-Soutn
Store2 bacon 87 100 97 100 0 0 0 0 0 0 C-Atlantic
Store2 tomato 16 100 26 100 0 0 0 0 0 0 C-Atlantic
Store2 TOTAL 103 200 123 200 0 0 0 0 0 0 C-Atlantic
D-Dunley TOTAL 103 200 123 200 0 0 0 0 0 0 C-Atlantic
Store3 bacon 89 100 99 100 0 0 0 0 0 0 C-Atlantic
Store3 tomato 18 100 28 100 0 0 0 0 0 0 C-Atlantic
Store3 TOTAL 107 200 127 200 0 0 0 0 0 0 C-Atlantic
D-Bingham TOTAL 107 200 127 200 0 0 0 0 0 0 C-Atlantic
R-15 James TOTAL 210 400 250 400 0 0 0 0 0 0 C-Atlantic
C-Atlantic TOTAL 210 400 250 400 0 0 0 0 0 0 C-AtlanticArthurZ thank you, it was just a minor bug:
(DT_DATE)(SUBSTRING("20001211", 1,4) + "-" + SUBSTRING("20001211",
5,2) + "-" + SUBSTRING("20001211",
7,2) )
Working fine now :) thanks!
Sorry if I caused it, but glad you found it
Arthur
MyBlog
Twitter -
Non-ANSI Outer Join Operator Issue (reposted due to text issues)
I am currently using Designer 11.5.0.0. Itu2019s XI Rel 2, but Iu2019m not sure what service pack. I have created several universes with outer joins against a SQL Server 2005 database, but when I try using them in a Crystal report, I get the following error:
Failed to retrieve date from the database. Details: 42000:[Microsoft][ODBC SQL Server Driver][SQL Server] The query uses non-ANSI outer join operators (u201C=u201D or u201C=u201D). To run this query without modification, please set the compatibility level for current database to 80 or lower, using stored procedure sp_dbcmptlevel. It is strongly recommended to rewrite the query using ANSI outer join operators (LEFT OUTER JOIN, RIGHT OUTER JOIN). In the future versions of SQL Server, non-ANSI join operators will not be supported even in backward-compatibility modes.
Here is my ODBC DSN configuration:
Microsoft SQL Server ODBC Driver Version 03.85.1132
Data Source Name: FlexOPS
Data Source Description:
Server: dalsvrw031
Database: (Default)
Language: (Default)
Translate Character
Data: Yes
Log Long Running Queries: No
Log Driver Statistics: No
Use Integrated Security: No
Use Regional Settings: No
Prepared Statements Option: Drop temporary procedures on disconnect
Use Failover Server: No
Use ANSI Quoted Identifiers: Yes
Use ANSI Null, Paddings and Warnings: Yes
Data Encryption: No
Okay, so I understand what the issue is. It appears that the version of Designer that I am using does not default the ANSI92 parameter to u201CYesu201D. So all the outer joins I have created in each of my universe are using the old *= as the join operator. And apparently, the ODBC driver I am using is not very happy with that.
As I understand it from what Iu2019ve read on other sites, I have the following options:
1) Set the ANSI92 parameter to Yes, drop all my joins, close and re-open Designer, and recreate all of the joins.
2) Find a different driver or connectivity method that will support non-ANSI joins.
3) Set my database back to SQL 2000 compatibility.
Option 1 is unappealing as it will cause a lot of time redoing all the work that Iu2019ve spent the past month doing. Option 2 is only a band-aid fix at best. Option 3 really isnu2019t an option for us.So I am wondering what other options I have to change these non-ANSI joins to ANSI compatible joins. Do I need to update Designer with a service pack? Is there a script out there that will automatically do this in each of the universes? I would appreciate any suggestions or guidance on this.
Thanks,
Lee -
Non-ANSI Outer Join Operator Issue
I am currently using Designer 11.5.0.0. Itu2019s XI Rel 2, but Iu2019m not sure what service pack. I have created several universes with outer joins against a SQL Server 2005 database, but when I try using them in a Crystal report, I get the following error:
Failed to retrieve date from the database.
Details: 42000:[Microsoft][ODBC SQL Server Driver][SQL Server] The query uses non-ANSI outer join operators (u201C=u201D or u201C=u201D). To run this query without modification, please set the compatibility level for current database to 80 or lower, using stored procedure sp_dbcmptlevel. It is strongly recommended to rewrite the query using ANSI outer join operators (LEFT OUTER JOIN, RIGHT OUTER JOIN). In the future versions of SQL Server, non-ANSI join operators will not be supported even in backward-compatibility modes.
Here is my ODBC DSN configuration:
Microsoft SQL Server ODBC Driver Version 03.85.1132
Data Source Name: FlexOPS
Data Source Description:
Server: dalsvrw031
Database: (Default)
Language: (Default)
Translate Character Data: Yes
Log Long Running Queries: No
Log Driver Statistics: No
Use Integrated Security: No
Use Regional Settings: No
Prepared Statements Option: Drop temporary procedures on disconnect
Use Failover Server: No
Use ANSI Quoted Identifiers: Yes
Use ANSI Null, Paddings and Warnings: Yes
Data Encryption: No
Okay, so I understand what the issue is. It appears that the version of Designer that I am using does not default the ANSI92 parameter to u201CYesu201D. So all the outer joins I have created in each of my universe are using the old *= as the join operator. And apparently, the ODBC driver I am using is not very happy with that.
As I understand it from what Iu2019ve read on other sites, I have the following options:
1) Set the ANSI92 parameter to Yes, drop all my joins, close and re-open Designer, and recreate all of the joins.
2) Find a different driver or connectivity method that will support non-ANSI joins.
3) Set my database back to SQL 2000 compatibility.
Option 1 is unappealing as it will cause a lot of time redoing all the work that Iu2019ve spent the past month doing. Option 2 is only a band-aid fix at best. Option 3 really isnu2019t an option for us.
So I am wondering what other options I have to change these non-ANSI joins to ANSI compatible joins. Do I need to update Designer with a service pack? Is there a script out there that will automatically do this in each of the universes?
I would appreciate any suggestions or guidance on this.
Thanks,
Lee
Edited by: Lee Vance on Jul 6, 2009 10:02 PMHi,
try the following:
open your universe in the Universe designer, go to File->Parameter, select the Parameter tab and change the value of the ANSI92 parameter from No to Yes.
Regards,
Stratos -
Help on - convert ansi sql to oracle sql
hi gurus,
i'm try'g to convert ansi sql to oracle sql.
but i'm getting an error. can u please let me know, if i can convert it or is it better to use ansi sql!
original code in ansi format::
select distinct bfc.NBR_SEQ, bfc.IDN_ENTITY, bfc.CDE_TYPE_ENTITY, n.CDE_STATUS,
gec.idn_group as idn_parent_id, bfc.IDN_FUNC_BUSS,
case when bfc.CDE_TYPE_ENTITY = 'P' OR bfc.CDE_TYPE_ENTITY = 'A' then
PKG_FW_NVGTR.GET_NAM_PAGE(bfc.IDN_ENTITY)
else
PKG_FW_NVGTR.GET_NAM_GROUP(bfc.IDN_ENTITY)
end as ENTITY_NAM,
p.Category, p.Display_Txt, p.show_in_nav, p.page_uri
from
T_BUSS_FUNC_ENTITY_CREF bfc
inner join t_buss_func bf on bfc.idn_func_buss = bf.idn_func_buss
inner join t_entity_prog_cref epc on bfc.idn_entity = epc.idn_entity and bfc.cde_type_entity = epc.cde_type_entity
left outer join t_page p on bfc.idn_entity = p.idn_page
left outer join t_group_entity_cref gec on bfc.idn_entity = gec.idn_entity and bfc.cde_type_entity = gec.cde_type_entity
left outer join t_nvgtr n on bfc.idn_entity = n.idn_entity and bfc.cde_type_entity = n.cde_type_entity
where
BF.nam_func_buss = 'CP' AND--P_NAM_FUNC_BUSS and
epc.cde_program in
( select p.cde_program from t_program p where p.nam_program in (
SELECT * FROM TABLE (CAST(PKG_FW_NVGTR.FN_GET_ARRAY_FROM_COMMA_LIST('LC', ',') AS TYP_ARRAY))))
order by
bfc.NBR_SEQ;tried to convert into oracle
SELECT DISTINCT bfc.NBR_SEQ,
bfc.IDN_ENTITY,
bfc.CDE_TYPE_ENTITY,
n.CDE_STATUS,
gec.idn_group as idn_parent_id,
bfc.IDN_FUNC_BUSS,
case when bfc.CDE_TYPE_ENTITY = 'P' OR bfc.CDE_TYPE_ENTITY = 'A' then
PKG_FW_NVGTR.GET_NAM_PAGE(bfc.IDN_ENTITY)
else
PKG_FW_NVGTR.GET_NAM_GROUP(bfc.IDN_ENTITY)
end as ENTITY_NAM,
p.Category,
p.Display_Txt,
p.show_in_nav,
p.page_uri
FROM T_BUSS_FUNC_ENTITY_CREF bfc,
T_BUSS_FUNC bf,
T_ENTITY_PROG_CREF epc,
T_PAGE p,
T_GROUP_ENTITY_CREF gec,
T_NVGTR n
WHERE bfc.IDN_FUNC_BUSS = bf.IDN_FUNC_BUSS
AND bfc.IDN_ENTITY = epc.IDN_ENTITY
AND bfc.CDE_TYPE_ENTITY = epc.CDE_TYPE_ENTITY
AND bfc.IDN_ENTITY(+) = p.IDN_PAGE
AND bfc.IDN_ENTITY(+) = gec.IDN_ENTITY
AND bfc.CDE_TYPE_ENTITY(+) = gec.CDE_TYPE_ENTITY
AND bfc.IDN_ENTITY(+) = n.IDN_ENTITY
AND bfc.CDE_TYPE_ENTITY(+) = n.CDE_TYPE_ENTITY
AND BF.nam_func_buss = 'CP' AND--P_NAM_FUNC_BUSS and
epc.cde_program in
( select p.cde_program from t_program p where p.nam_program in (
SELECT * FROM TABLE (CAST(PKG_FW_NVGTR.FN_GET_ARRAY_FROM_COMMA_LIST('LC', ',') AS TYP_ARRAY))))
order by
bfc.NBR_SEQ;error is
ORA-01417: a table may be outer joined to at most one other tableso how can i convert it?
thanksuser642856 wrote:
explain plan for this select statement
ID PID Operation Name Rows Bytes Cost CPU Cost IO Cost Temp space IN-OUT PQ Dist PStart PStop
0 SELECT STATEMENT 10M 1183M 570694 33G 567917
1 0 SORT UNIQUE 10M 1183M 287940 17G 286502 2607M
2 1 HASH JOIN 10M 1216M 179 1G 84
3 2 COLLECTION ITERATOR PICKLER FETCH PKG_FW_NVGTR.FN_GET_ARRAY_FROM_COMMA_LIST
4 2 HASH JOIN OUTER 2693 299K 58 34M 55
5 4 HASH JOIN OUTER 37 3959 11 24M 9
6 5 HASH JOIN OUTER 37 3663 10 18M 8
7 6 HASH JOIN 37 1147 7 12M 6
8 7 HASH JOIN 59 1180 5 6060823 4
9 8 NESTED LOOPS 2 24 3 15843 3
10 9 TABLE ACCESS BY INDEX ROWID T_BUSS_FUNC 1 6 1 8341 1
11 10 INDEX UNIQUE SCAN UK_NAM_FUNC_BUSS 1 0 1050 0
12 9 TABLE ACCESS FULL T_PROGRAM 2 12 2 7501 2
13 8 INDEX FULL SCAN PK_T_ENTITY_PROG_CREF 59 472 1 18921 1
14 7 TABLE ACCESS FULL T_BUSS_FUNC_ENTITY_CREF 37 407 2 14891 2
15 6 TABLE ACCESS FULL T_PAGE 26 1768 2 14141 2
16 5 INDEX FULL SCAN UK_UNIQUE_GROUP_DEPENDENT 26 208 1 12321 1
17 4 TABLE ACCESS FULL T_NVGTR 6986 47K 46 3179613 46 as you can see.. cpu cost is in 33G..
is there any better way?
thanksCan you run this in a session please:
ALTER SESSION set optimizer_dynamic_sampling = 4;Then run an explain plan again.
And you have a function in there - PKG_FW_NVGTR.FN_GET_ARRAY_FROM_COMMA_LIST - which isn't helping things. -
ANSI SQL 92 SYNTAX OUTER JOIN PERFORMANCE ISSUE
Good Morning
Could anyone explain why the excution time for these two (ment to be identical)
queries run so differently.
oracle syntax execution time 1.06 seconds
select COUNT(*) from
PL_EVENT_VIEW pev,
PL_EVENT_STAFF_VIEW pesv
WHERE pev.EVENT_ID=PESV.EVENT_ID(+)
AND pev.WEEKS=PESV.WEEK_NUM(+)
AND pev.event_id=2520
ansi sql 92 syntax execution time 7.05 seconds
select COUNT(*) from
PL_EVENT_VIEW pev
LEFT JOIN PL_EVENT_STAFF_VIEW pesv
ON (pev.EVENT_ID=PESV.EVENT_ID
AND pev.WEEKS=PESV.WEEK_NUM)
WHERE pev.event_id=2520
Thanks
David HillsBTW Oracle outer join operator (+) and ANSI SQL OUTER JOIN syntax are NOT equivalent. Consider following:
DROP TABLE T1;
CREATE TABLE T1 (C1 NUMBER);
DROP TABLE T2;
CREATE TABLE T2 (C2 NUMBER);
DROP TABLE T3;
CREATE TABLE T3 (C3 NUMBER);
-- Following SELECT works:
SELECT COUNT(*)
FROM T1, T2, T3
WHERE C2 = C1
AND C3(+) = C1
COUNT(*)
0
-- But:
SELECT COUNT(*)
FROM T1, T2, T3
WHERE C2 = C1
AND C3(+) = C1
AND C3(+) = C2
AND C3(+) = C1
ERROR at line 4:
ORA-01417: a table may be outer joined to at most one other table
-- However with ANSI syntax:
SELECT COUNT(*)
FROM T1
JOIN T2 ON (C2 = C1)
LEFT JOIN T3 ON (C3 = C1 AND C3 = C2)
COUNT(*)
0 -
ANSI SQL Syntax - What belongs to join-clause and what to where-clause
Hello,
we currently have a discussion about the ANSI SQL Syntax where we do not agree what belongs to the join clause and what belongs to the where clause in an ANSI Sytnax SQL Query.
Lets say there is a query like this:
+SELECT *+
FROM employees emp, departments dept
WHERE emp.dept_country = dept.dept_country
AND emp.dept_name = dept.dept_name
AND dept.dept_type = 'HQ'
AND emp.emp_lastname = 'Smith'
Primary key of the departments table is on the columns dept_country, dept_name and dept_type. We have a Oracle database 10g.
Now I have rewritten the query to Ansi Syntax:
+SELECT *+
FROM employees emp
JOIN departments dept
ON emp.dept_country = dept.dept_country AND emp.dept_name = dept.dept_name
WHERE dept.dept_type = 'HQ'
AND emp.emp_lastname = 'Smith'
Another developer says that this is not completely correct, every filter on a column that belongs to the primary-key of the joined table has to be in the join clause, like this:
+SELECT *+
FROM employees emp
JOIN departments dept
+ON emp.dept_country = dept.dept_country AND emp.dept_name = dept.dept_name AND dept.dept_type = 'HQ'
WHERE emp.emp_lastname = 'Smith'
Can somebody tell me which on is correct?
Is there any definition for that? I couldn't find it in the Oracle Database definition.
I just found out the names of the ANSI documents here: http://docs.oracle.com/cd/B19306_01/server.102/b14200/ap_standard_sql001.htm#i11939
I had a look at the ANSI webstore but there you have to buy the PDF files. In my case thats exaggerated because both of the Queries work and i am just interessted if there is one correct way.
Thank you in advance
MarcoHi,
As i guideline i would say, answer the question: should the result of the join be filtered or should only filtered rows be joined from a particular table?
This is helpful in the case of outer joins also, for inner joins it doesnt matters as said already be former posters, where there may be hughe semantical differences depending of where the predicates are placed.
From performance view, if we talk about oracle, take a look a the execution plans. You will see that there is (probably) no difference in case of inner joins. Even in case of outer joins the optimizer pushes the predicate as a filter towards the table if it semantically possible.
Regards -
Outer join query for SQL server from Oracle
Hi All,
My question is regarding making queries from Oracle to SQL Server database thorugh DBLink.
In my oracle database I have a DBLink emp.world for SQL Server database.
I need to query SQL Server data from oracle (so that this query can be combined with other oracle tables).
Query is given below:
SELECT
a."EmpID" as "Employee ID",
a."EmpStatus" "Employee Status"
b."EmpSub" as "Employee Subjects"
FROM
[email protected] a
left outer join [email protected] b on a."EmpID" = b."suEmpID"
ORDER BY a."EmpID";My problem is when I run the same query from oracle, it does not show the EmpID that does not exist in Subjects table, but when run from actual SQL Server database, it shows all the records.
Samples are given below:
Run from Oracle
Employee ID Employee Status Employee Subjects
101 Active Maths
102 Active Maths
102 Active Physics
104 Inactive Chemistry
Run form SQL Server
Employee ID Employee Status Employee Subjects
101 Active Maths
102 Active Maths
102 Active Physics
103 Active NULL
104 Inactive ChemistryI am not sure why in oracle outer join for SQL server tables is not working. What is the right way for outer join in this case.
I am using oracle database 10gR2 and SQL Server 2005.
Please Help.
Thanks.SELECT
a."EmpID" as "Employee ID",
a."EmpStatus" "Employee Status"
b."EmpSub" as "Employee Subjects"
FROM
[email protected] a
left outer join [email protected] b on a."EmpID" = b."suEmpID"
ORDER BY a."EmpID";
http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/queries006.htm#sthref3175
From your description, it appears you may need a right outer join. You want to get back all the rows from 'B', not from 'A'. Try a right join and let us know. -
ANSI SQL to Oracle Old SQL conversion
I need help to convert this ANSI SQL Query to Oracle Old school (With inline views and =(+) joins and where clasuses)
CUrrent Query and new one should return same resultset
---------------------------------Query Start----------------------------------------------------
SELECT COUNT(*)
FROM
SELECT
'XXXXXX' as Big_Boss,
da.Direct,
da.Director,
da.Manager,
da.SubArea,
da.Project,
da.Project_Name,
da.Project_Class,
da.HISL,
da.Resource_Name,
da.Resource_Status,
da.mon,
to_char(sysdate, 'dd-Mon-YYYY') AS "Current_Date",
DECODE(da.Project, NULL, 0, round(da.Slice / da.month_total, 2)) as
"Approved_Demand",
SUM(da.Availability) as "Headcount"
FROM
SELECT
w.level4_name AS Direct,
w.level5_name AS Director,
w.level6_name AS Manager,
w.level7_name AS SubArea,
INV.Code as Project,
inv.name as Project_Name,
det.hum_project_gate as Project_Class,
r.id AS HISL,
r.full_name as Resource_Name,
lookup.lookup_code as Resource_Status,
alc.slice AS Slice,
alc.slice_date as Mon,
avl.slice AS month_total,
alc.slice / avl.slice as FTE,
count(distinct r.id) AS Availability
FROM
nbi_dim_obs w,
prj_blb_slices_m_avl avl,
prj_obs_units obs,
cmn_lookups lookup,
srm_resources r
************** Section to be Converted ***************************----------
----------------------------Start----------------------------------------------------
left outer join(prj_resources t inner join srm_resources res on
t.prprimaryroleid = res.id) on r.id = t.prid
left outer join(prj_blb_slices_m_alc alc
left outer join(prteam tm
inner join(inv_investments INV inner join odf_ca_project det on det.id = inv.id
and det.hum_project_gate = 'approved_for_development') on tm.prprojectid = INV.ID
and INV.Is_Active = 1) on alc.prj_object_id = tm.prid
and alc.investment_id = inv.id) on alc.resource_id = t.prid
--------------------------------------End--------------------------------------------
-- inner join prj_blb_slices_m_avl avl on alc.resource_id = avl.prj_object_id
-- inner join prj_obs_units obs on res.unique_name = obs.unique_name
-- inner join nbi_dim_obs w on w.level7_unit_id = obs.id
WHERE
w.obs_type_name = 'Workgroup'
AND alc.slice > 0
AND alc.slice_date = avl.slice_date
AND r.is_active = 1
AND r.person_type = lookup.id
AND w.level7_unit_id = obs.id
AND alc.resource_id = avl.prj_object_id
AND res.unique_name = obs.unique_name
GROUP BY
w.level4_name
, w.level5_name
, w.level6_name
, w.level7_name
, r.id
, r.full_name
, lookup.lookup_code
, inv.code
, inv.NAME
, det.hum_project_gate
, alc.slice_date
, alc.slice
, avl.slice
) DA
GROUP BY
da.direct
, da.director
, da.manager
, da.subarea
, da.project_class
, da.hisl
, da.resource_name
, da.resource_status
, da.project
, da.Project_Name
, da.mon
, da.availability
, da.slice
, da.month_total
ORDER BY
da.direct
, da.director
, da.manager
, da.subarea
-------------------------------Query End----------------------------------------------------------Joins are joins ... what do you mean by "nested" joins?
If you are concerned about outer joins that can be performed using ANSI syntax that are not supported in the classic Oracle syntax then use in-line view and outer join the views.
If your code was properly formatted it would be possible for someone to read it and possibly see what you are seeing.
Read the FAQ page and learn to format your posted code. -
Differences between ANSI SQL and Oracle 8/9
Hallo,
i'm looking for good online texts or books concerning the problem "Differences between ANSI SQL and different database implementations (ORACLE, Informix, MySQL...)" I want to check a program written in C (with ESQL) that works with an Informix-DB. In this code i want to find code that is specific to the Informix-DB. I want to change the database, so all the code should be independent from a DB. Does anybody know texts or books concerning this problem?
thx
Marco SeumBasically there is syntax difference between both of them.
Lets say i want to join two table EMP and DEPT based on DEPTNO.
With Oracle SQL format its like this.
select e.*
from emp e, dept d
where e.deptno = d.deptnoHere the joining condition goes in the WHERE clause.
With ANSI SQL format its like this.
select e.*
from emp e
join dept d
on e.deptno = d.deptnoHere the join condition is mentioned separately and not in WHERE clause.
Oracle supports ANSI SQL starting from 9i version.
You can read more about the syntax difference Here -
Oracle 8i -multiple LEFT OUTER JOIN
Hi,
I have to convert some stored procedure from Sql Server to Oracle 8i where I have multiple LEFT OUTER JOIN on a table. Because Oracle 8i accept only one outer join on a table how can I convert this:
select a.id, b.id
from test as a LEFT JOIN test1 b ON a.id(+)=b.id
and a.display(+)=b.display
and a.name(+)='Done';
Thanks.FROM test a LEFT JOIN test1 b ON b.key = a.keyis equivalent to
FROM test a, test1 b WHERE b.key(+) = a.keyThere is a restriction (when using the "(+)" syntax) that a table may be outer-joined to at most one other table, but that does not prevent you from having multiple join conditions between those two tables.
From your example I'm not sure whether you need this:
SELECT a.id, b.id
FROM test a
, test1 b
WHERE a.name = 'Done'
AND b.id (+)= a.id
AND b.display (+)= a.display;or this:
SELECT a.id, b.id
FROM test1 b
, test a
WHERE a.id (+)= b.id
AND a.display (+)= b.display;
WHERE a.name (+)= 'Done'; -
What is Difference between ANSI SQL and ORACLE SQL
Hi,
I am going to take the assesment test for ANSI SQL Programming before that i want to know any difference between ANSI SQL and ORACLE SQL?
I am studying for SQL but the test will be ANSI SQL please let me give an idea about the both.
Thanks
Merina RoslinBasically there is syntax difference between both of them.
Lets say i want to join two table EMP and DEPT based on DEPTNO.
With Oracle SQL format its like this.
select e.*
from emp e, dept d
where e.deptno = d.deptnoHere the joining condition goes in the WHERE clause.
With ANSI SQL format its like this.
select e.*
from emp e
join dept d
on e.deptno = d.deptnoHere the join condition is mentioned separately and not in WHERE clause.
Oracle supports ANSI SQL starting from 9i version.
You can read more about the syntax difference Here
Maybe you are looking for
-
I use a 500G WD as my external.. I have documents and movies there that i do not want to delete. Simply i just want to delete my time machine files completely and for my mac to not recognised it as a time machine HD.. TY guys p.s. A video would be n
-
I tried changing persona made no difference Bookmarks toolbar showing in sidebar with default and added bookmarks
-
Why are photos not appearing complete when in PDf/preview mode for purchasing a photobook?
Everything appears perfect in the project mode, but when I went to order I got an error message from customer support. When I check the book in Preview my photos are coming up with scratchy white marks throughout. Almost all are super hi-res so tha
-
How do i get desktop icons out of the hide mode???
my baby got on my computer and started pressing the keyboard and now my icons are hidden. i have only had my computer for 6 days so i have no idea how to get the icons from the hide mode. when i put the cursor down to the bottom of the desktop the ic
-
Hi Friends, I am new to XI. I am practicing File to File scenario. https://www.sdn.sap.com/irj/sdn/wiki?path=/display/xi/flatFILETOFLATFILE& I struck, please guide me. I am able to create Product, BS, SWCC, Data types, messages types, Mapping, Messag