Use ansi join syntax

From what i have been reading is better to use the new syntax(dont know how new it is)

The ANSI join syntax was new to Oracle in Oracle 8i in 1998 - that's 15 years old.
It can produce more readable code, and is both more readable and less human-error prone for outer joins.
The ANSI format lets you outer join between multiple tables in a way the old oracle-specific ( + ) syntax did not and introduces FULL OUTER JOIN which you should use very rarely.
You should not use NATURAL JOIN in code - adding unrelated columns to the tables involved can make it give very different results.
There have not been significant bugs for ANSI joins in Oracle since Oracle 10.2 was introduced about 8 years ago.
As Paul said, the ON part should be the join criteria between the tables. The were clause should be the filtering of the joined tables.
So assuming start_date, end_date and in_property_id are variables
SELECT resv_num, unit_date
    FROM p_resv_unit ru
    INNER JOIN p_pm_unit_night pun
    ON pun.resv_unit_id = ru.resv_unit_id
    WHERE pun.property_id = in_property_id
    AND pun.unit_date BETWEEN start_date AND end_date
    AND pun.pm_unit_num = cvUnitNum;
If start_date and end_date were columns in p_resv_unit the query would be:
SELECT resv_num, unit_date
    FROM p_resv_unit ru
    INNER JOIN p_pm_unit_night pun
    ON pun.resv_unit_id = ru.resv_unit_id AND pun.unit_date BETWEEN ru.start_date AND ru.end_date
    WHERE pun.property_id = in_property_id
        AND pun.pm_unit_num = cvUnitNum;
Inner join queries work with criteria in the wrong place, but they're harder to read. Outer joins don't work unless you put the criteria in the right place.

Similar Messages

  • Flow accept error when using ANSI join syntax

    Hi
    I had a region populated by a query joining two views (one in-line using connect by). When trying to create the region if the join was coded using ANSI syntax (INNER JOIN .... USING) I got a flow accept error when either trying to proceed using the wizard, or apply changes when editing the region.
    After changing to the old style Oracle join (using predicates), I was able to create the region and everything worked ok. I found the solution after reading this post Error 404 wwv_flow.accept was not found in which the OP says he would raise a bug. Did the bug get raised? I ask since his problem arose whilst he was selecting from a view using ANSI joins and using instead of triggers, and I was joining an in-line view to a view using ANSI joins and instead of triggers, but neither view has been changed, just the join syntax. The view defined in the database is used in other regions and works fine. This could indicate the OP's problem was fixed, but one still exists.
    Incidentally this is the only time I have used non-ANSI joins in the entire apex app - the rest work!. Unfortunately it is impossible for me to demo the app.
    Richard
    using ApEx 3.0.1.00.07 and 10g (10.2.0.1) EE on Wintel

    Tyler,
    Apologies, what I was trying to say was that I couldn't put the application on the Oracle APEX site.
    Yes, I do have a work-around, but that does not mean a bug may still exist. I count myself fortunate I saw that post and, therefore, experimented with the syntax of the join - there is no reason APEX should not accept ANSI join conditions, in fact , it does. The ANSI-joined SQL statement executed perfectly in TOAD and SQL*Plus, but I could not even save it in APEX.
    regards
    Richard

  • Difference between oracle join syntaxes and ANSI join syntaxes

    What is difference between oracle join syntaxes and ANSI join syntaxes ?
    why oracle is having different syntaxes for joins than ANSI syntaxes ?
    Also Join syntaxes are different in some oracle vesrions ?

    BluShadow wrote:
    3360 wrote:
    Yes it is. The Oracle database wasn't initially designed to be ANSI compliant. As you correctly state the ANSI standards weren't around when it was initially designed, so the statement is perfectly correct. ;)Ok, in one sense it may be correct but it is a completely misleading statement. Not sure why you think it's misleading.Because there was no ANSI standard, so making it sound like a design choice The Oracle database wasn't initially designed to be ANSI compliant. would suggest to most readers that there was a standard to be compliant to.
    Like saying Ford originally did not design their cars to incorporate safety features such as ABS, seat belts and air bags.
    The OP asked "why oracle is having different syntaxes for joins than ANSI syntaxes ?" and the answer is that Oracle wasn't initially designed with ANSI compliance, so it has it's old non-ANSI syntax,As shown above, the old syntax was ANSI compliant at the time and to call it non-ANSI is either incorrect or misleading dependent on your point of view.
    and since ANSI syntax became the standard it now supports that. And since ANSI switched to a new standard, Oracle had to implement the new standard as well as the previous ANSI standard would be more accurate in my opinion.
    Nothing misleading as far as I'm aware in that.I find the whole discussion about ANSI and Oracle's supposed non-compliance, reads like it was Oracle's choice to deviate from the standards, when it was ANSI's bullheaded decisions to pointlessly change standards that left Oracle and other vendors out of compliance, and that was a decision made solely by ANSI.
    This is probably the reason ANSI no longer produces SQL standards, the endless syntax fiddling would eventually have made forward left under outer joins a reality.
    {message:id=1785128}

  • Joining multiple tables using ANSI join

    Hi,
    I need to join 4 tables using ANSI join. Lets say they are A,B,C adn D. A and B has a common column called x. C and D had a common column called y. I wrote a query like this
    select * from A left outer join B on (A.x=B.x),
    C left outer join D on (C.y =D.y)
    its not working!!!
    I need to use ANSI join.
    can any body help me please???

    Hi,
    But is there is any common column between A,C or B,C or D,A?
    Let me know.

  • ANSI join syntax with code-insight

    I've noticed that SQL Developer 1.1.3 doesn't perform code-insight into table aliases when I use the ANSI join sytax. Is there a configuration option to make this possible or does it just not exist yet?

    Hi,
    Currently on SQL Developer 1.2, Windows XP, and Database 9.2
    I have the same problem too.
    The Code-Insight is unable to show the Code Completion for aliased table name in ANSI JOIN
    SELECT *
    FROM    Schema1.Table1 t1
    INNER JOIN Schema1.Table2 t2 ON t2.     -- cannot show the code-insightHowever the following code works just fine for the code-insight
    SELECT *
    FROM    Schema1.Table1 t1,
                  Schema1.Table2 t2
    WHERE t1.Field1 = t2.Field1Any suggestion?
    Regards,
    Buntoro

  • Solution  to work in ANSI Join Condition

    Hi All,
    I am having one query which is using ANSI join syntax.
    The table TMP_GL_DATA having 237 records, when I am running the below query giving 237 records only if I remove the condition
    key word ' WHERE 1=1 ', ELSE ITS GIVING 0 records.
    How to give where condition if we use more than one table join with single table.
    If any one have ideal please let me know..
    See the below query for your reference.
         SELECT *
         FROM TMP_GL_DATA
         left outer join FCT_TP_RATES ON TMP_GL_DATA.v_repline1_code = FCT_TP_RATES.v_repline1_code
         left outer join FCT_NONCUST_PROD_TP_RATES ON TMP_GL_DATA.v_repline1_code = FCT_NONCUST_PROD_TP_RATES.v_repline1_code
         AND TMP_GL_DATA.v_prod_code = FCT_NONCUST_PROD_TP_RATES.v_prod_code
         AND TMP_GL_DATA.v_gl_ccy_code = FCT_NONCUST_PROD_TP_RATES.v_ccy_code
         inner join DIM_PRODUCT ON TMP_GL_DATA.v_prod_code = DIM_PRODUCT.v_prod_code
         left outer join VW_EFP_ADJ_RECORDS ON TMP_GL_DATA.v_gl_code = VW_EFP_ADJ_RECORDS.v_gl_code
         AND TMP_GL_DATA.v_lv_code = VW_EFP_ADJ_RECORDS.v_lv_code
         AND TMP_GL_DATA.v_gl_ccy_code = VW_EFP_ADJ_RECORDS.v_gl_ccy_code
         AND TMP_GL_DATA.v_branch_code = VW_EFP_ADJ_RECORDS.v_branch_code
         WHERE 1=1
         AND TMP_GL_DATA.V_GL_TYPE IN (Fn_I18n('L', 48),Fn_I18n('L', 51))
         AND TMP_GL_DATA.v_process_flag = 'A'
         AND TMP_GL_DATA.fic_mis_date = TO_DATE('20060601','YYYYMMDD')
         AND dim_product.f_latest_record_indicator = 'Y'
         AND fct_tp_rates.fic_mis_date = (SELECT MAX(fic_mis_date)
         FROM fct_tp_rates a
         WHERE a.v_repline1_code = a.v_repline1_code
         AND a.fic_mis_date <= TO_DATE('20060601','YYYYMMDD'))
         AND fct_noncust_prod_TP_RATES.FIC_MIS_DATE = (SELECT MAX(FIC_MIS_DATE)
         FROM fct_noncust_prod_tp_rates a
                                                                WHERE a.v_repline1_code = v_repline1_code
                                                                AND a.v_prod_code = v_prod_code
                                                                AND a.v_ccy_code = v_ccy_code
                                                                AND a.fic_mis_date <=TO_DATE('20060601','YYYYMMDD'))

    if you query is something like this that is giving you 0 records:
    SELECT *
      FROM TMP_GL_DATA
      left outer join FCT_TP_RATES ON TMP_GL_DATA.v_repline1_code = FCT_TP_RATES.v_repline1_code
      left outer join FCT_NONCUST_PROD_TP_RATES ON TMP_GL_DATA.v_repline1_code = FCT_NONCUST_PROD_TP_RATES.v_repline1_code
                 AND TMP_GL_DATA.v_prod_code = FCT_NONCUST_PROD_TP_RATES.v_prod_code
                 AND TMP_GL_DATA.v_gl_ccy_code = FCT_NONCUST_PROD_TP_RATES.v_ccy_code
      inner join DIM_PRODUCT ON TMP_GL_DATA.v_prod_code = DIM_PRODUCT.v_prod_code
      left outer join VW_EFP_ADJ_RECORDS ON TMP_GL_DATA.v_gl_code = VW_EFP_ADJ_RECORDS.v_gl_code
                 AND TMP_GL_DATA.v_lv_code = VW_EFP_ADJ_RECORDS.v_lv_code
                 AND TMP_GL_DATA.v_gl_ccy_code = VW_EFP_ADJ_RECORDS.v_gl_ccy_code
                 AND TMP_GL_DATA.v_branch_code = VW_EFP_ADJ_RECORDS.v_branch_code
       AND TMP_GL_DATA.V_GL_TYPE IN (Fn_I18n('L', 48),Fn_I18n('L', 51))
       AND TMP_GL_DATA.v_process_flag = 'A'
       AND TMP_GL_DATA.fic_mis_date = TO_DATE('20060601','YYYYMMDD')
       AND dim_product.f_latest_record_indicator = 'Y'
       AND fct_tp_rates.fic_mis_date = (SELECT MAX(fic_mis_date)
                                          FROM fct_tp_rates a
                                         WHERE a.v_repline1_code = a.v_repline1_code
                                           AND a.fic_mis_date <= TO_DATE('20060601','YYYYMMDD'))
                                           AND fct_noncust_prod_TP_RATES.FIC_MIS_DATE = (SELECT MAX(FIC_MIS_DATE)
                                                                                           FROM fct_noncust_prod_tp_rates a
                                                                                          WHERE a.v_repline1_code = v_repline1_code
                                                                                            AND a.v_prod_code = v_prod_code
                                                                                            AND a.v_ccy_code = v_ccy_code
                                                                                            AND a.fic_mis_date <=TO_DATE('20060601','YYYYMMDD'))you might want to try this:
    SELECT *
      FROM TMP_GL_DATA
      left outer join FCT_TP_RATES ON TMP_GL_DATA.v_repline1_code = FCT_TP_RATES.v_repline1_code
      left outer join FCT_NONCUST_PROD_TP_RATES ON TMP_GL_DATA.v_repline1_code = FCT_NONCUST_PROD_TP_RATES.v_repline1_code
                 AND TMP_GL_DATA.v_prod_code = FCT_NONCUST_PROD_TP_RATES.v_prod_code
                 AND TMP_GL_DATA.v_gl_ccy_code = FCT_NONCUST_PROD_TP_RATES.v_ccy_code
      inner join DIM_PRODUCT ON TMP_GL_DATA.v_prod_code = DIM_PRODUCT.v_prod_code
      left outer join VW_EFP_ADJ_RECORDS ON TMP_GL_DATA.v_gl_code = VW_EFP_ADJ_RECORDS.v_gl_code
                 AND TMP_GL_DATA.v_lv_code = VW_EFP_ADJ_RECORDS.v_lv_code
                 AND TMP_GL_DATA.v_gl_ccy_code = VW_EFP_ADJ_RECORDS.v_gl_ccy_code
                 AND TMP_GL_DATA.v_branch_code = VW_EFP_ADJ_RECORDS.v_branch_code
    WHERE TMP_GL_DATA.V_GL_TYPE IN (Fn_I18n('L', 48),Fn_I18n('L', 51))
       AND TMP_GL_DATA.v_process_flag = 'A'
       AND TMP_GL_DATA.fic_mis_date = TO_DATE('20060601','YYYYMMDD')
       AND dim_product.f_latest_record_indicator = 'Y'
       AND fct_tp_rates.fic_mis_date = (SELECT MAX(fic_mis_date)
                                          FROM fct_tp_rates a
                                         WHERE a.v_repline1_code = a.v_repline1_code
                                           AND a.fic_mis_date <= TO_DATE('20060601','YYYYMMDD'))
                                           AND fct_noncust_prod_TP_RATES.FIC_MIS_DATE = (SELECT MAX(FIC_MIS_DATE)
                                                                                           FROM fct_noncust_prod_tp_rates a
                                                                                          WHERE a.v_repline1_code = v_repline1_code
                                                                                            AND a.v_prod_code = v_prod_code
                                                                                            AND a.v_ccy_code = v_ccy_code
                                                                                            AND a.fic_mis_date <=TO_DATE('20060601','YYYYMMDD'))

  • ANSI/9i Join Syntax and Pretty Code

    I've always tried to keep my SQL statement code formatted in a way that I think helps readability. I picked up the following style because I found it easy to quickly find the FROM clause and the JOINS or conditions:
    select e.ename,
           e.sal,
           d.dname
    from   emp e,
           dept d
       * Joins
    where  e.deptno = d.deptno
       * Conditions
    and    d.dname = 'SALES'
    /Of course, for such a simple query I wouldn't have used the comments to divide the WHERE clause into joins and conditions...
    Anyway, since Tom Kyte and the 9i documentation suggest using the ANSI join syntax (amongst other reasons), I have decided to begin changing my ways. However, I am having troubles figuring out how to format my SQL to still be "pretty."
    For the previous example, a new formatting style seems easy:
    select e.ename,
           e.sal,
           d.dname
    from   emp e
      join dept d          on e.deptno = d.deptno
    where  d.dname = 'SALES'
    /Now, when we use an example that has optional joins is where I can't figure what my style should be:
    select e.ename,
           m.ename as manager
    from        emp e
      left join emp m      on e.mgr = m.empno
    where  e.deptno = 10
    /I don't really like this style since it gets so wide, causing problems when indenting for subqueries/inline-views. It also looks kinda clunky because the tables are indented more than everything else...
    Anyway, since I don't want to spend a bunch of time figuring out things like style, I'd like to see what other formats people are using. I'd appreciate seeing how others are formatting thier SQL when using the new 9i (old-ANSI) syntax.
    Thanks, Stan

    That looks to me like left aligned (but I may be on the wrong side of the looking glass...)
    By preference is to left-align the KEYWORDS and the data words, using indentation to distinguish the start of the different clauses (SELECT, FROM, WHERE, ORDER BY, etc.). This approach is easily standardised with Textpad or similar editing tools. Quite how one programs a text editor to turn one's code into a Rorschach blot is beyond me.
    I haven't done much with ANSI joins, so I hadn't come up with a standard for layout. The following is what I think I would do if I ever had to, and is basically an adaption of what I do now ...
    FROM   user_indexes i
           , user_ind_columns ic2
           , user_tab_columns c2with the ANSI join stuff indented and aligned. I find rigourous application of UPPER and lower case tends to assist clarity: indentation and alignment are not enough.
    SELECT i.table_name
           , i.index_name
           , ic2.column_position
    FROM   user_indexes i
           INNER JOIN user_ind_columns ic2
           ON i.table_name = ic2.table_name
           AND i.index_name = ic2.index_name
           INNER JOIN user_tab_columns c2
           ON ic2.table_name = c2.table_name
           AND ic2.column_name = c2.column_name
    WHERE  i.uniqueness='UNIQUE'
    ORDER  BY i.table_name
           , i.index_name
           , ic2.column_position
    /

  • Bug in JOIN syntax? (oracle 9i)

    Hi,
    take these three tables:
    MASTER (id NUMBER, name VARCHAR2(10))
    DETAIL (id NUMBER, master_id NUMBER)
    SUBDETAIL (id NUMBER, detail_id NUMBER, name VARCHAR(10)
    When I perform this query:
    SELECT SUBDETAIL.id as did, MASTER.id as mid
    FROM SUBDETAIL
    JOIN DETAIL ON (SUBDETAIL.detail_id = DETAIL.id)
    JOIN MASTER ON (DETAIL.master_id = MASTER.id)
    WHERE
    name = 'joe';
    I would expect the parser to give me 'column ambiguously defined' (because the 'name' field from the whereclause is defined in both subdetail and master).
    However, it does not say that. Instead, it assumes that it should use the name field from master. This is confusing, as this could easily lead to mistakes (as it did in my application)
    Greetings,
    Ivo

    There seems to be a difference between the way Oracle resolves column names using the ANSI join syntax and Oracle's syntax. It appears that Oracle does not know about the columns, until it processes each join, and further, the last table joined seems to be sued to resolve nameing conflicts. Consider:
    SQL> SELECT * FROM master;
            ID NAME
             1 joe
    SQL> SELECT * FROM subdetail;
            ID  DETAIL_ID NAME
             1          2 fred
    SQL> SELECT * FROM detail;
            ID  MASTER_ID
             2          1
    SQL> SELECT subdetail.id AS did, master.id AS mid
      2  FROM subdetail
      3       JOIN detail ON (subdetail.detail_id = detail.id)
      4       JOIN master ON (detail.master_id = master.id)
      5  WHERE name = 'joe';
           DID        MID
             1          1
    SQL> SELECT subdetail.id AS did, master.id AS mid
      2  FROM subdetail
      3       JOIN detail ON (subdetail.detail_id = detail.id)
      4       JOIN master ON (detail.master_id = master.id)
      5  WHERE name = 'fred';
    no rows selected
    So, it is clearly going after master.name. However,
    SQL> SELECT subdetail.id AS did, master.id AS mid
      2  FROM detail
      3       JOIN master ON (master.id = master_id)
      4       JOIN subdetail ON (subdetail.detail_id = detail.id)
      5  WHERE name = 'joe'
    no rows selected
    But,
    SQL> SELECT subdetail.id AS did, master.id AS mid
      2  FROM detail
      3       JOIN subdetail ON (subdetail.detail_id = detail.id)
      4       JOIN master ON (master.id = master_id)
      5  WHERE name = 'joe'
           DID        MID
             1          1
    Old style syntax gives:
    SQL> SELECT subdetail.id AS did, master.id AS mid
      2  FROM subdetail, detail, master
      3  WHERE subdetail.detail_id = detail.id and
      4        detail.master_id = master.id and
      5        name = 'joe';
          name = 'joe'
    ERROR at line 5:
    ORA-00918: column ambiguously defined
    and note that
    SQL> SELECT subdetail.id AS did, master.id AS mid
      2  FROM subdetail
      3      JOIN master ON (detail.master_id = master.id)
      4      JOIN detail ON (subdetail.detail_id = detail.id)
      5  WHERE name = 'joe'
        JOIN master ON (detail.master_id = master.id)
    ERROR at line 3:
    ORA-00904: invalid column nameSo, in ANSI syntax, order matters, and whatever the syntax good testing matters.
    TTFN
    John

  • Oracle 9i ansi joins

    Hi
    We are using oracle 9i database ,i want to use asni full outer join for below query .PLease any one how to use ?
    SELECT COLL_SUB_NMBR AS COLL_NO, CLCOLTP, SSUCYL AS CTRY_CD
    FROM TGDW_SGSSUTTRNP, TGDW_PAR_COLL
    WHERE TGDW_PAR_COLL.COLL_SUB_NMBR = TGDW_SGSSUTTRNP.COLLNO
    AND TGDW_PAR_COLL.COLL_TYPE = TGDW_SGSSUTTRNP.CLCOLTP
    AND TGDW_PAR_COLL.COLL_TYPE IN ( 1,21)
    UNION ALL
    SELECT COLL_SUB_NMBR AS COLL_NO, CLCOLTP, FDGCYBNK AS CTRY_CD
    FROM TGDW_SGFDGTRNP, TGDW_PAR_COLL
    WHERE TGDW_PAR_COLL.COLL_SUB_NMBR = TGDW_SGFDGTRNP.COLLNO
    AND TGDW_PAR_COLL.COLL_TYPE = TGDW_SGFDGTRNP.CLCOLTP
    AND TGDW_PAR_COLL.COLL_TYPE = 2
    Regards
    MM

    select COLL_SUB_NMBR, CLCOLTP, a.SSUCYL, b.FDGCYBNK from
    ( TGDW_SGSSUTTRNP join TGDW_PAR_COLL on
        (TGDW_PAR_COLL.COLL_SUB_NMBR = TGDW_SGSSUTTRNP.COLLNO TGDW_PAR_COLL.COLL_TYPE = TGDW_SGSSUTTRNP.CLCOLTP
    AND TGDW_PAR_COLL.COLL_TYPE IN ( 1,21)) a
    full outer join
    ( TGDW_SGFDGTRNP join TGDW_PAR_COLL on
        (TGDW_PAR_COLL.COLL_SUB_NMBR = TGDW_SGFDGTRNP.COLLNO AND TGDW_PAR_COLL.COLL_TYPE = TGDW_SGFDGTRNP.CLCOLTP AND TGDW_PAR_COLL.COLL_TYPE = 2)) b
    using (COLL_SUB_NMBR, CLCOLTP);This is not the same query, because the original query is not using outer join but it may help to figure out on how to use the ansi join syntax
    Regards
    Laurent Schneider
    OCM DBA

  • Using ANSI sql in forms 9i triggers

    hi,
    could use some help here please!
    I am getting errors when trying to compile triggers in forms 9i against a 9i DB which include cursors or sql select's which are written using the ANSI join syntax.
    example:
    declare
    cursor cur_test is
    select dual1.dummy "dual1", dual2.dummy "dual2"
    from (dual dual1 inner join dual dual2 on dual1.dummy = dual2.dummy);
    begin
         null;
    end;
    when I try and compile I get error message "103" which seems to think that the SQL is not valid. If I put the same statements into recordgroups they will compile, and they run via SQL*Plus OK.
    versions are:
    Forms [32 Bit] Version 9.0.2.9.0 (Production)
    Oracle9i Enterprise Edition Release 9.2.0.1.0 - 64bit Production
    With the Partitioning, OLAP and Oracle Data Mining options
    JServer Release 9.2.0.1.0 - Production
    Oracle Toolkit Version 9.0.4.0.23 (Production)
    PL/SQL Version 9.0.1.3.1 (Production)
    Oracle Procedure Builder V9.0.2.0.7 Build #1022 - Production
    database: 9.2.0.1.0
    Any ideas?!
    thanks,
    Pete

    If you remember that Sybase and MS worked together on SQLServer. Version 6.5 was pretty much the same database server. MS then built version 7.0 leaving Sybase behind. They added ANSI standard joins to their db. What did they get? PROBLEMS. Every patch contained fixes for ANSI standard joins. Even SQLServer 2000 has problems with it.
    Oracle now trys to follow MS and add ANSI joins to their database. What did it give them? BUGS. Remember this one?
    select * from sys.role$ cross join dual
    http://otn.oracle.com/deploy/security/pdf/sql_joins_alert.pdf
    Use standard joins and not ANSI joins. That will solve this problem.

  • Using outter joins

    need to create a report based on three tables: emp,dept, and loc. There dept can have null dept and loc and the user wants to see these records; therefore, we need to do an outter join. Also, the user wants to have bind variables so he/she can put any of these variables (dept or loc) and based on that return the records.
    select emp.name, dept.name, loc.name
    from emp, dept, loc
    where dept.deptno = emp.deptno(+)
    and loc.locid = emp.loc(+)
    and dept.deptno = :department
    and loc.locid = :location
    I need to find and join those records that are null. I took the following approach, but I'm not sure if this is correct:
    1. created a table based on emp and converted those null dept and loc w/ -1
    2. joined the tables
    3. do the query based on the table
    4. the bind variable will have a like so that if the user doesn't insert a field I will have the wild card (%) so it will bring all records
    select emp.name, dept.name, loc.name
    from emp, dept, loc, (select nvl(deptno, -1) as deptno, nvl(loc, -1) as loc from emp) temp
    where dept.deptno = emp.deptno(+)
    and loc.locid = emp.loc(+)
    and temp.deptno = nvl(dept.deptno, -1)
    and temp.loc = nvl(loc.id, -1)
    and temp.deptno like nvl(:department, '%')
    and temp.locid like nvl(:location, '%')
    I think that I'm overdoing this query though. Let me know!
    ;-P
    Marcelo

    Hi, since oracle 9i it is possible to use the ansi join syntax in Oracle sql.
    You can use a "full out join", "left outer join", "right outer join"
    Example return all rows with NULLs from all tables:
    select e.last_name, d.department_name, d.department_id, j.job_title, l.city
    from employees e
         full outer join departments d on (e.department_id=d.department_id )
         full outer join jobs j on (e.job_id=j.job_id)
         full outer join locations l on (l.location_id=d.location_id)
    see docu: http://download-west.oracle.com/docs/cd/B10501_01/server.920/a96540/statements_103a.htm#2107297
    Lutz

  • Help with ansi joins

    hi all
    i have this query in which i have used ansi joins,not an expert though on ansi joins ...got to knw abt ansi joins only today
    SELECT abc.vendor_number, abc.vendor_name, api.invoice_amount,
           api.invoice_date, api.invoice_type_lookup_code, api.invoice_num,
           avp.prepay_number, api.description,   --,avp.INVOICE_CURRENCY_CODE CCY,
                                              aup.prepay_amount_applied,
           aup.prepay_amount_remaining,
           SUM (-avp.prepay_amount_remaining * NVL (api.exchange_rate, 1)
               ) prepaid_available,
           '1234' voucher_number
      FROM ap_invoices_v api INNER JOIN ap_invoice_distributions_v aid ON (    api.invoice_id =
                                                                                  aid.invoice_id
                                                                           AND api.invoice_type_lookup_code =
                                                                                  'PREPAYMENT'
                                                                           AND api.invoice_num =
                                                                                  '5'
                                                                          ), ap_invoices_v api LEFT OUTER JOIN ap_apply_prepays_v avp ON (api.invoice_id =
                                                                                                                                             avp.invoice_id
           ap_invoices_v api INNER JOIN ap_checks_v abc ON (abc.vendor_id =
                                                                     api.vendor_id
                                                           ), ap_invoice_payments abb LEFT OUTER JOIN ap_apply_prepays_v avp ON (abb.invoice_id =
                                                                                                                                    avp.invoice_id
           ap_invoice_distributions_v aid LEFT OUTER JOIN ap_unapply_prepays_v aup ON (aid.invoice_distribution_id =
                                                                                          aup.prepay_distribution_id
           ap_unapply_prepays_v aup LEFT OUTER JOIN ap_apply_prepays_v avp ON (aup.prepay_distribution_id =
                                                                                  avp.invoice_distribution_id
                                                                              ), ap_invoices_v api INNER JOIN ap_invoice_payments abb ON (abb.invoice_id =
                                                                                                                                         api.invoice_id
                                                                                                                                     )i am getting column ambigously
    defined in the select clause,is there another way to refer to the columns?
    kindly guide
    thanking in advance
    Edited by: makdutakdu on Dec 20, 2011 11:28 AM

    what is it?
    ap_invoices_v api INNER JOIN ap_invoice_distributions_v aid ON (    api.invoice_id =
                                                                                  aid.invoice_id
                                                                           AND api.invoice_type_lookup_code =
                                                                                  'PREPAYMENT'
                                                                           AND api.invoice_num =
                                                                                  '5'
                                                                          ), ap_invoices_v api LEFT OUTER JOIN ap_apply_prepays_v avp ON (api.invoice_id =
                                                                                                                                             avp.invoice_id
    ..use
    ap_invoices_v api INNER JOIN ap_invoice_distributions_v aid ON (    api.invoice_id =
                                                                                  aid.invoice_id
                                                                           AND api.invoice_type_lookup_code =
                                                                                  'PREPAYMENT'
                                                                           AND api.invoice_num =
                                                                                  '5'
                                                                          ) LEFT OUTER JOIN ap_apply_prepays_v avp ON (api.invoice_id =
                                                                                                                                             avp.invoice_id
    ...

  • OMWB 9.2 should use ANSI syntax on joins

    Currently, SQL Server2000 code like:
    -- Start of SQL Server code snippet
    from sf_add_on
    join sf_add_on_descr
    on sf_add_on_descr.code = sf_add_on.code
    and sf_add_on_descr.language_code = @an_language_code
    left outer join sf_blob
    on sf_blob.filename = 'AddOnSetting'
    -- End of SQL Server code snippet
    is converted to:
    -- Start of Oracle code snippet
    FROM sa.sf_add_on, sa.sf_add_on_descr, sa.sf_blob
                             WHERE (sf_add_on_descr.code = sf_add_on.code and sf_add_on_descr.language_code
              = ap_adm_aos_sel.an_language_code_) AND (sf_blob.filename (+)=
              'AddOnSetting')
    -- End of Oracle code snippet
    This is in contradiction with the 9iRel2 documentation:
    "Oracle Corporation recommends that you use the FROM clause OUTER JOIN syntax rather than the Oracle join operator"
    Is there going to be an option to use the "old" (8-compatible) syntax versus the 9i (ANSI) syntax?

    Frank,
    Bug 2846362 - PARSER OPTION REQUIRED FOR ANSII COMPLIANT JOINS TO ORACLE 9I DATABASE
    This parser option has been added to code in development, I am not sure when this will be released as a production release.
    Regards,
    Turloch
    Oracle Migration Workbench Team

  • LEFT OUTER JOIN multiple tables - using the 9i syntax

    I've always written my queries using the (+) operator for outer joins. I want to start using the new ANSI standard available in 9i. I can do it when I'm joining two tables in a simple query, but how does it work when I am joining multiple tables?
    Here is an example of some SQL that works with the (+) outer join syntax. How can I convert this to use the LEFT OUTER JOIN syntax?
    SELECT *
    FROM audit_entry aue,
    audit_table aut,
    audit_statement aus,
    audit_row aur,
    audit_row_pkey aup1,
    audit_row_pkey aup2
    WHERE aue.audit_entry_id = aus.audit_entry_id
    AND aut.table_name = 'TEST_AUDITING'
    AND aut.table_owner = 'CLA_JOURNAL'
    AND aus.audit_table_id = aut.audit_table_id
    AND aur.audit_statement_id (+) = aus.audit_statement_id
    AND aup1.audit_row_id (+) = aur.audit_row_id
    AND aup1.pk_column_name (+) = 'TEST_AUDTING_PK_1'
    AND aup2.audit_row_id (+) = aur.audit_row_id
    AND aup2.pk_column_name (+) = 'TEST_AUDITING_PK_2'
    I can join audit_statement to audit_entry easy enough, but then I want to join audit_table to audit_statement, how do I do that, do I start nesting the join statements?
    Thanks
    Richard

    Thanks for getting back so quickly, I have tried the suggested SQL with mixed results:
    SELECT COUNT(*)
    FROM audit_entry aue
    JOIN audit_statement aus ON aue.audit_entry_id = aus.audit_entry_id
    JOIN audit_table aut ON aus.audit_table_id = aut.audit_table_id
    RIGHT OUTER JOIN audit_row aur ON aur.audit_statement_id = aus.audit_statement_id
    RIGHT OUTER JOIN audit_row_pkey aup1 ON aup1.audit_row_id = aur.audit_row_id
    RIGHT OUTER JOIN audit_row_pkey aup2 ON aup2.audit_row_id = aur.audit_row_id
    WHERE aut.table_name = 'TEST_AUDITING_TWO'
    AND aut.table_owner = 'CLA_JOURNAL'
    AND aup1.pk_column_name = 'TEST_AUDTING_PK_1'
    AND aup2.pk_column_name = 'TEST_AUDITING_PK_2'
    I had to change the order slightly, between the first two JOINs but otherwise it executed OK. My problem is, it should only return 175 rows but its returning 30625 rows. If I comment out the second reference to audit_row_pkey I get the expected result:
    SELECT COUNT(*)
    FROM audit_entry aue
    JOIN audit_statement aus ON aue.audit_entry_id = aus.audit_entry_id
    JOIN audit_table aut ON aus.audit_table_id = aut.audit_table_id
    RIGHT OUTER JOIN audit_row aur ON aur.audit_statement_id = aus.audit_statement_id
    RIGHT OUTER JOIN audit_row_pkey aup1 ON aup1.audit_row_id = aur.audit_row_id
    --RIGHT OUTER JOIN audit_row_pkey aup2 ON aup2.audit_row_id = aur.audit_row_id
    WHERE aut.table_name = 'TEST_AUDITING_TWO'
    AND aut.table_owner = 'CLA_JOURNAL'
    AND aup1.pk_column_name = 'TEST_AUDTING_PK_1'
    --AND aup2.pk_column_name = 'TEST_AUDITING_PK_2'
    It looks the same condition is being used in each case but why do I suddenly get so many rows - its joining differently somehow. It must be to do with the order, do I need to bracket the query?
    Thanks again
    Richard

  • While using the Old syntax of outer join i encountered Ora-01719 error .

    This is quite strange when i used the Old way of using Outer Joins(+), i encountered the Ora-01719 error saying Outer Joins not allowed in Or and IN operator.Whereas when i use the ANSI sql i query gets executed without any error.Any idea what might be the reason..is it that i myself is making mistake.
    Please find the select statement below..
    SELECT d4.c2, d4.c8, vw_rpt_prod_ln_grp.prod_grp_desc, d4.c10, d4.c5, d4.c3,
    CASE
    WHEN d4.c6 = 'Closed'
    THEN d4.c6
    WHEN d4.c6 = 'Closed (w/o Action)'
    THEN d4.c6
    WHEN d4.c6 =
    'Closed, Supporting Process(es) Active'
    THEN d4.c6
    WHEN d4.c6 = 'Cancelled'
    THEN d4.c6
    WHEN t3.workflow_compnt_id = 1
    THEN 'Definition'
    WHEN t3.workflow_compnt_id = 2
    THEN 'Root Cause'
    WHEN t3.workflow_compnt_id = 3
    THEN 'Solution'
    WHEN t3.workflow_compnt_id = 4
    THEN 'Implementation'
    WHEN t3.workflow_compnt_id = 5
    THEN 'Feedback'
    WHEN t3.workflow_compnt_id = 9
    THEN 'Preliminary Root Cause'
    WHEN t3.workflow_compnt_id = 2001
    THEN 'Report'
    WHEN t3.workflow_compnt_id = 2002
    THEN 'Sent'
    WHEN t3.workflow_compnt_id = 2003
    THEN 'Add. Info Needed'
    WHEN t3.workflow_compnt_id = 2004
    THEN 'Open'
    WHEN t3.workflow_compnt_id = 2007
    THEN 'Solution Feedback'
    END issue_workflow_status,
    CASE
    WHEN d4.c6 = 'Closed'
    THEN 0
    WHEN d4.c6 = 'Closed (w/o Action)'
    THEN 0
    WHEN d4.c6 =
    'Closed, Supporting Process(es) Active'
    THEN 0
    WHEN d4.c6 = 'Cancelled'
    THEN 0
    ELSE t3.workflow_compnt_id
    END issue_workflow_status_code,
    d4.c6, d4.c9,
    CASE t3.issue_step_status_cd
    WHEN 'In Progress'
    THEN t3.step_target_submit_dt
    WHEN 'Needs Additional Information'
    THEN t3.step_target_submit_dt
    WHEN 'Awaiting Approval'
    THEN t3.step_target_closed_dt
    ELSE NULL
    END target_date,
    CASE
    WHEN CASE t3.issue_step_status_cd
    WHEN 'In Progress'
    THEN t3.step_target_submit_dt
    WHEN 'Needs Additional Information'
    THEN t3.step_target_submit_dt
    WHEN 'Awaiting Approval'
    THEN t3.step_target_closed_dt
    ELSE NULL
    END IS NULL
    THEN 'N'
    WHEN CASE t3.issue_step_status_cd
    WHEN 'In Progress'
    THEN t3.step_target_submit_dt
    WHEN 'Needs Additional Information'
    THEN t3.step_target_submit_dt
    WHEN 'Awaiting Approval'
    THEN t3.step_target_closed_dt
    ELSE NULL
    END < TRUNC (CURRENT_DATE)
    THEN 'Y'
    ELSE 'N'
    END step_is_late,
    t3.orig_user_full_nm, t3.champ_user_full_nm, t3.champ_org_nm,
    vw_rpt_defntn.modl_yr_nbr, vw_rpt_vpps_lvl.level1_vpps_desc,
    vw_rpt_vpps_lvl.level2_vpps_desc, vw_rpt_vpps_lvl.level3_vpps_desc,
    vw_rpt_vpps_lvl.level4_vpps_desc,
    Mv_RPT_CONCAT_ENGN_OPTN_ALL.concat_engn_optn,
    vw_rpt_incdnt_src_three_level.level1_incdnt_src_desc,
    vw_rpt_incdnt_src_three_level.level2_incdnt_src_desc,
    vw_rpt_incdnt_src_three_level.level3_incdnt_src_desc,
    vw_rpt_warranty_labr_code.concat_warranty_labr_code_desc, d4.c4, d4.c7,
    vw_cust_survey_type.cust_survey_type_desc,
    vw_complaint_ctg.complaint_ctg_cd,
    vw_prob_main_cause.prob_main_cause_desc, soltn_step.confidence_lvl_id,
    d4.c12, d4.c13
    FROM (SELECT DISTINCT vw_rpt_issue.project_id c0,
    vw_rpt_issue.prts_prod_ln_id c1,
    vw_rpt_issue.issue_id c2,
    vw_rpt_issue.disply_issue_nbr c3,
    vw_rpt_issue.issue_sevrty_cd c4,
    vw_rpt_issue.proj_nbr c5,
    vw_rpt_issue.issue_status_cd c6,
    vw_rpt_issue.primry_metric_score_nbr c7,
    vw_rpt_issue.issue_type_cd c8, vw_rpt_issue.title c9,
    vw_rpt_issue.prts_prod_ln_desc c10,
    vw_rpt_leadtime.issue_id c11,
    vw_rpt_leadtime.definition_start_dt c12,
    vw_rpt_leadtime.definition_close_dt c13,
    vw_rpt_leadtime.root_cause_start_dt c14,
    vw_rpt_leadtime.root_cause_close_dt c15,
    vw_rpt_leadtime.solution_start_dt c16,
    vw_rpt_leadtime.solution_end_dt c17,
    vw_rpt_leadtime.implementation_start_dt c18,
    vw_rpt_leadtime.implementation_close_dt c19,
    vw_rpt_leadtime.feedback_start_dt c20,
    vw_rpt_leadtime.feedback_end_dt c21,
    vw_rpt_leadtime.prc_start_dt c22,
    vw_rpt_leadtime.prc_end_dt c23,
    defntn_step.issue_id c24,
    defntn_step.workflow_compnt_id c25,
    defntn_step.complaint_ctg_id c26,
    defntn_step.contnmt_actn_plan_id c27,
    defntn_step.direct_run_imprvm_pct c28,
    defntn_step.direct_run_loss_pct c29,
    defntn_step.drive_type_id c30,
    defntn_step.driving_cond_id c31,
    defntn_step.eng_pgm_nbr c32,
    defntn_step.engn_serial_nbr c33,
    defntn_step.envrnmtl_cond_id c34,
    defntn_step.ergo_rating_id c35,
    defntn_step.evaltn_complt_pct c36,
    defntn_step.evaltn_procdr_id c37,
    defntn_step.gca_50_or_safety_issue_flag c38,
    defntn_step.gca_value_amt c39,
    defntn_step.gm_rating_id c40,
    defntn_step.hardware_stage_id c41,
    defntn_step.incdnt_discvrd_by_nm c42,
    defntn_step.incdnt_discvr_dept_nm c43,
    defntn_step.incdnt_discvr_ph_nbr c44,
    defntn_step.incdnt_first_rptd_dt c45,
    defntn_step.incdnt_src_id c46,
    defntn_step.intrnl_measmt_info_owner_nm c47,
    defntn_step.intrnl_measmt_plt_faclty_id c48,
    defntn_step.intrnl_measmt_rpt_dt c49,
    defntn_step.issue_clasfn_id c50,
    defntn_step.issue_ctg_id c51,
    defntn_step.issue_intgrtn_id c52,
    defntn_step.modl_yr_id c53,
    defntn_step.modl_yr_qtr_id c54,
    defntn_step.odmtr_msmt_unit_id c55,
    defntn_step.odmtr_rdng_msmt_unit_id c56,
    defntn_step.odmtr_rdng_nbr c57,
    defntn_step.odmtr_rdng_beginning_nbr c58,
    defntn_step.odmtr_rdng_ending_nbr c59,
    defntn_step.part_drblty_msmt_unit_id c60,
    defntn_step.part_drblty_nbr c61,
    defntn_step.part_test_msmt_unit_id c62,
    defntn_step.part_test_nbr c63,
    defntn_step.pe_me_trial_issue_flag c64,
    defntn_step.pim_nbr c65,
    defntn_step.plt_asmbly_doc_nbr c66,
    defntn_step.productivity_nbr c67,
    defntn_step.suspect_parts_avbl_flag c68,
    defntn_step.suspect_parts_loc_txt c69,
    defntn_step.trnsmn_serial_nbr c70,
    defntn_step.veh_ident_nbr c71,
    defntn_step.veh_proprt_nbr c72,
    defntn_step.veh_test_msmt_unit_id c73,
    defntn_step.veh_test_nbr c74,
    defntn_step.vpps_id_nbr c75,
    defntn_step.wrkstn_id c76,
    defntn_step.road_surface_id c77,
    defntn_step.cost_redctn_rpt_dt c78,
    defntn_step.cost_redctn_trackg_nbr c79,
    defntn_step.cost_redctn_type_id c80,
    defntn_step.cust_survey_dt c81,
    defntn_step.warnty_impct_rpt_dt c82,
    defntn_step.field_prod_rpt_nbr c83
    FROM (SELECT DISTINCT mv_rpt_issue_all.project_id
    project_id,
    mv_rpt_issue_all.prts_prod_ln_id
    prts_prod_ln_id,
    mv_rpt_issue_all.issue_id issue_id,
    mv_rpt_issue_all.disply_issue_nbr
    disply_issue_nbr,
    mv_rpt_issue_all.issue_sevrty_cd
    issue_sevrty_cd,
    mv_rpt_issue_all.proj_nbr proj_nbr,
    mv_rpt_issue_all.issue_status_cd
    issue_status_cd,
    mv_rpt_issue_all.primry_metric_score_nbr
    primry_metric_score_nbr,
    mv_rpt_issue_all.issue_type_cd
    issue_type_cd,
    mv_rpt_issue_all.title title,
    mv_rpt_issue_all.prts_prod_ln_desc
    prts_prod_ln_desc
    FROM mv_rpt_issue_all,
    vw_sec_acs_grp_proj acs_grp_proj
    WHERE acs_grp_proj.acs_grp_id IN
    (1,
    4,
    42,
    43,
    44,
    51,
    52,
    53,
    54,
    266,
    366,
    386,
    526,
    546,
    547,
    548,
    566,
    846,
    946,
    966,
    1006,
    1066,
    1087
    AND mv_rpt_issue_all.prts_prod_ln_id =
    acs_grp_proj.prts_prod_ln_id
    AND mv_rpt_issue_all.project_id =
    acs_grp_proj.project_id
    AND mv_rpt_issue_all.issue_type_cd =
    'Current Production') vw_rpt_issue,
    vw_rpt_leadtime,
    vw_defntn_step defntn_step
    WHERE vw_rpt_issue.issue_id = vw_rpt_leadtime.issue_id
    AND vw_rpt_issue.issue_id = defntn_step.issue_id) d4,
    vw_rpt_incdnt_src_three_level,
    vw_rpt_warranty_labr_code,
    vw_rpt_prod_ln_grp,
    (SELECT t1.issue_id issue_id, t1.workflow_compnt_id workflow_compnt_id,
    t1.issue_step_status_cd issue_step_status_cd,
    t1.step_target_closed_dt step_target_closed_dt,
    t1.step_target_submit_dt step_target_submit_dt,
    t1.orig_user_full_nm orig_user_full_nm,
    t1.champ_user_full_nm champ_user_full_nm,
    t1.champ_org_nm champ_org_nm
    FROM prts_syst.vw_rpt_issue_step_dtl_all t1
    WHERE t1.current_step_flag = 'Y') t3,
    vw_complaint_ctg,
    root_cause_step,
    vw_prob_main_cause,
    Mv_RPT_CONCAT_ENGN_OPTN_ALL,
    vw_rpt_vpps_lvl,
    soltn_step,
    vw_rpt_defntn_all vw_rpt_defntn,
    vw_cust_survey_impct_dtl cust_survey_impct_dtl,
    vw_cust_survey_type
    WHERE d4.c46 = vw_rpt_incdnt_src_three_level.level3_incdnt_src_id(+)
    Or d4.c46=vw_rpt_incdnt_src_three_level.level2_incdnt_src_id(+))
    And vw_rpt_incdnt_src_three_level.level3_incdnt_src_id IS NULL
    AND d4.c2 = vw_rpt_warranty_labr_code.issue_id(+)
    AND d4.c1 = vw_rpt_prod_ln_grp.prts_prod_ln_id(+)
    AND d4.c2 = t3.issue_id(+)
    AND d4.c26 = vw_complaint_ctg.complaint_ctg_id(+)
    AND d4.c2 = root_cause_step.issue_id(+)
    AND root_cause_step.prob_main_cause_id = vw_prob_main_cause.prob_main_cause_id(+)
    AND d4.c2 = Mv_RPT_CONCAT_ENGN_OPTN_ALL.issue_id(+)
    AND d4.c75 = vw_rpt_vpps_lvl.vpps_id_nbr(+)
    AND d4.c2 = soltn_step.issue_id(+)
    AND d4.c2 = vw_rpt_defntn.issue_id(+)
    AND d4.c2 = cust_survey_impct_dtl.issue_id(+)
    AND cust_survey_impct_dtl.cust_survey_type_id = vw_cust_survey_type.cust_survey_type_id(+)
    AND vw_rpt_prod_ln_grp.prod_grp_desc IN
    ('DB Admin', 'GM - All Vehicles', 'GMAP - DAT', 'GMAP - Holden')
    AND d4.c6 IN
    ('Cancelled',
    'Closed',
    'Closed (w/o Action)',
    'Closed, Supporting Process(es) Active',
    'Draft',
    'Open'
    );

    Hi,
    Maestro_Vineet wrote:
    This is quite strange when i used the Old way of using Outer Joins(+), i encountered the Ora-01719 error saying Outer Joins not allowed in Or and IN operator.Whereas when i use the ANSI sql i query gets executed without any error.Any idea what might be the reason..is it that i myself is making mistake.No, I don't think you're making any mistake. Some things are simply not allowed with the "+" outer-join syntax.
    There are work-arounds, but they are harder to code and slower to run than simply using ANSI syntax.
    I recommend always using ANSI syntax, especially for outer joins.

Maybe you are looking for