ANSI SQL syntax?

Hi all,
I have a simple query
SELECT A.*, B.Dstrct_Code FROM MSF601 A, MSF600 B
WHERE ALTERNATE_REF LIKE 'PF%'
AND A.alt_ref_code = B.Equip_No
AND B.Dstrct_Code = 'ACME';
which works fine, but I want to convert it to ANSI
SQL syntax, so I tried
SELECT A.*, B.Dstrct_Code FROM MSF601 A, MSF600 B
WHERE ALTERNATE_REF LIKE 'PF%'
INNER JOIN ON A.alt_ref_code = B.Equip_No
AND B.Dstrct_Code = 'ACME';
but I get
ERROR at line 3:
ORA-00933: SQL command not properly ended
Could some kind soul explain why?
Paul...

An example that looks a lot like your example:
SQL> select dept.*
  2       , emp.ename
  3    from dept, emp
  4   where dept.dname like '%A%'
  5   inner join on dept.deptno = emp.deptno
  6     and emp.sal > 1000
  7  /
inner join on dept.deptno = emp.deptno
FOUT in regel 5:
.ORA-00933: SQL command not properly ended
SQL> select dept.*
  2       , emp.ename
  3    from dept
  4         inner join emp on dept.deptno = emp.deptno
  5   where dept.dname like '%A%'
  6     and emp.sal > 1000
  7  /
                                DEPTNO DNAME          LOC           ENAME
                                    30 SALES          CHICAGO       ALLEN
                                    30 SALES          CHICAGO       WARD
                                    20 RESEARCH       DALLAS        JONES
                                    30 SALES          CHICAGO       MARTIN
                                    30 SALES          CHICAGO       BLAKE
                                    10 ACCOUNTING     NEW YORK      CLARK
                                    20 RESEARCH       DALLAS        SCOTT
                                    10 ACCOUNTING     NEW YORK      KING
                                    30 SALES          CHICAGO       TURNER
                                    20 RESEARCH       DALLAS        ADAMS
                                    20 RESEARCH       DALLAS        FORD
                                    10 ACCOUNTING     NEW YORK      MILLER
12 rijen zijn geselecteerd.Regards,
Rob.

Similar Messages

  • 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
    Marco

    Hi,
    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

  • How to generate ANSI SQL syntax mapping

    I am not able to force OWB to generate ANSI SQL syntax mapping.
    In mapping configuration I have checked "ANSI SQL syntax" On, "Operating mode" is "Set based fail over to row based", "Optimize code" is On.
    "PLSQL generation mode" is set to 10gR2.
    OWB 10.2.0.4.36, OraDB 10.2.0.4.0

    Oracle SQL is based on ANSI sql 92 standards. But not possible to generate queries in ansi sql 92 format?

  • ANSI SQL Syntax Vs Old Syntax

    Hi,
    Is there a performance difference between ansi and old syntax.
    The following query
    SELECT ITD.display_description
    FROM structure_child SC
    RIGHT OUTER JOIN structure S ON SC.structure_id = S.structure_id
    INNER JOIN structure_level SL ON SL.structure_level_id = S.structure_level_id
    INNER JOIN item_type_naming ITN ON ITN.structure_id = S.structure_id
    INNER JOIN item_type_description ITD ON ITN.item_type_description_id = ITD.item_type_description_id
    AND item_type_id = p_item_type_id
    WHERE ( S.structure_id = p_structure_id OR S.structure_id = 0)
    and itd.item_type_id = p_item_type_id
    ORDER BY structure_level
    Runs much slower than the old style query
    SELECT ITD.DISPLAY_DESCRIPTION
    FROM structure S, structure_child SC, structure_level SL,item_type_naming ITN,
    item_type_description ITD
    WHERE SC.structure_id(+) = S.structure_id
    AND SL.structure_level_id = S.structure_level_id
    AND ITN.structure_id = S.structure_id
    AND ITN.item_type_description_id = ITD.item_type_description_id
    AND item_type_id = p_item_type_id
    AND (S.structure_id = p_structure_id OR S.structure_id = 0)
    ORDER BY structure_level
    Any reasons why this is the case. Also is there any hint I can give to improve the performance.

    They ought to be the same.
    Be sure to run the query twice to ensure the extra time doesn't including parsing, etc.
    Do you get the same results?
    Are the explain/execution plans the same?
    The only caveat I can think of with ANSI joins is that there is a problem using them over a dblink in which one of the remote tables has a LOB column, an error is generated it that case...
    Steve

  • Oracle SQL / Ansi SQL

    Hey,
    one of my colleagues managed to create a SQL-statement (in ansi-sql-syntax) that just blocks the session and gives no response at all.
    When I rewrote the statement, it gave results within a second.
    It's not quite possible to provide a sample-case, but maybe someone here has an idea why the first statement doesn't work, and the second does?
    First:
    ====
    SELECT c.CONTRACTID as ENTITEITID,
    v.VASTSTELLINGCODE,
    '' as INFO,
    v.CAMPAGNE
    FROM NFD_CONTRACT c
    INNER JOIN NFD_OVK o ON o.OVKID = c.OVKID
    INNER JOIN NFD_VSTDEFCMP v ON v.VASTSTELLINGCODE = 'C77' AND v.CLASSIFICATIECODE = o.CLASSIFICATIECODE AND v.CAMPAGNE = o.CAMPAGNE
    AND Nfd_Vaststellingen_Pck.NFD_IS_DATUM_VST_VALID('C77',o.CAMPAGNE,'Contract',o.CLASSIFICATIECODE) = 1
    INNER JOIN NFD_BETROKKENPSN_CON psn ON c.CONTRACTID = psn.CONTRACTID
    INNER JOIN (SELECT a.aangifteid, a.psn_nmr, a.psnrolid, a.oogstjaar,
    case when exists (SELECT ENTITEITID FROM NFD_VST_OA04_V vst WHERE a.AANGIFTEID = vst.ENTITEITID) then 1
    when exists (SELECT ENTITEITID FROM NFD_VST_OA05_V vst WHERE a.AANGIFTEID = vst.ENTITEITID) then 1
    when exists (SELECT ENTITEITID FROM NFD_VST_OA06_V vst WHERE a.AANGIFTEID = vst.ENTITEITID) then 1
    else 0
    end AS OA_Heeft_E
    FROM NFD_AANGIFTE a
    WHERE AANGIFTETYPE = 'Oogstaangifte') vst ON psn.PSN_NMR = vst.PSN_NMR AND psn.PSNROLID = vst.PSNROLID
    AND o.CAMPAGNE = vst.OOGSTJAAR AND vst.OA_Heeft_E = 1
    Second:
    ======
    SELECT c.CONTRACTID as ENTITEITID,
    v.VASTSTELLINGCODE,
    '' as INFO,
    v.CAMPAGNE
    FROM NFD_CONTRACT c
    ,nfd_ovk o
    ,nfd_vstdefcmp v
    ,nfd_betrokkenpsn_con psn
    ,(SELECT a.aangifteid, a.psn_nmr, a.psnrolid, a.oogstjaar,
    case when exists (SELECT ENTITEITID FROM NFD_VST_OA04_V vst WHERE a.AANGIFTEID = vst.ENTITEITID) then 1
    when exists (SELECT ENTITEITID FROM NFD_VST_OA04M_V vst WHERE a.AANGIFTEID = vst.ENTITEITID) then 1
    when exists (SELECT ENTITEITID FROM NFD_VST_OA04S_V vst WHERE a.AANGIFTEID = vst.ENTITEITID) then 1
    when exists (SELECT ENTITEITID FROM NFD_VST_OA05_V vst WHERE a.AANGIFTEID = vst.ENTITEITID) then 1
    when exists (SELECT ENTITEITID FROM NFD_VST_OA06_V vst WHERE a.AANGIFTEID = vst.ENTITEITID) then 1
    else 0
    end AS OA_Heeft_E
    FROM NFD_AANGIFTE a
    WHERE AANGIFTETYPE = 'Oogstaangifte') vst
    WHERE o.OVKID = c.OVKID
    AND v.VASTSTELLINGCODE = 'C77' AND v.CLASSIFICATIECODE = o.CLASSIFICATIECODE AND v.CAMPAGNE = o.CAMPAGNE
    AND Nfd_Vaststellingen_Pck.NFD_IS_DATUM_VST_VALID('C77',o.CAMPAGNE,'Contract',o.CLASSIFICATIECODE) = 1
    AND c.CONTRACTID = psn.CONTRACTID
    AND psn.PSN_NMR = vst.PSN_NMR AND psn.PSNROLID = vst.PSNROLID
    AND o.CAMPAGNE = vst.OOGSTJAAR AND vst.OA_Heeft_E = 1

    hey riedelmie,
    off course the second statement is different.
    I rewrote the query so the inner joins are being replaced by where-clauses with the table-names all in the from-clause.
    In the second statement there are two extra when-clauses but they should also be in the first statement (the problem is still there, so data could indeed be different, but the problem is the same)
    Tnx.
    Greetings,
    Dave
    Message was edited by:
    geysemansdave
    added text about the when-clauses

  • 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 Hills

    BTW 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

  • 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 Seum

    Basically 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

  • 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 Roslin

    Basically 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

  • 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}

  • 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.

  • Iso/ansi sql-99 query

    hi..
    i'm new for oracle ..
    i hav one doubt .. what is the difference between normal join and iso/ansi sql-99 joins...
    is any advantage ..
    query e.g:
    SELECT c.course_name, c.period, e.student_name
    FROM course c, enrollment e
    WHERE c.course_name = e.course_name(+)
    AND c.period = e.period(+);
    sql-99 format :
    SELECT c.course_name, c.period, e.student_name
    FROM enrollment e RIGHT OUTER JOIN course c
    ON c.course_name = e.course_name
    AND c.period = e.period;

    Hi
    -It is analogous to joining a table, and avoiding the "where" clause
    -It allows easier product migration and a reduced learning curve when cross-training
    -there is no performance increase compared to the existing syntax.
    I hope u got it
    Khurram Siddiqui
    [email protected]

  • Generate ANSI SQL with Oracle IKM

    Is it possible for ODI to generate ANSI SQL with the Oracle IKM?
    I have used ANSI joins in a filter in an interface, now when I run the interface I get the error: ORA-25156: old style outer join (+) cannot be used with ANSI joins.
    I would prefer to use ANSI joins in my filters instead of the old style (+) syntax. Is this possible?

    Sure,
    Go to topology, edit your Oracle technology , on SQL tab change it over to ordered joins - clause location - From , you can specify the keywords left join, right join, full outer join etc to get rid of your '(+)'

  • Ansi SQL for "select ... for update nowait"

    Hi, All,
    I have a sql
    select ... for update nowait
    My boss wants it to be ANSI compliant.
    I am not familiar with ANSI SQL.
    What should be the syntax in Ansi?
    Thanks a lot!

    I resent having the lowest salary :-)Sorry John, it's probably due to the exchange rate of sterling against the canuck dollar right now.
    SQL> select empno, ename, sal, job, mgr from emp;
         EMPNO ENAME             SAL JOB              MGR
          7369 SPENCER           800 CLERK           7902
          7499 VERREYNNE        1600 SALESMAN        7698
          7521 VAN WIJK         1250 SALESMAN        7698
          7566 MAINGUY          2975 MANAGER         7839
          7654 KISHORE          1250 SALESMAN        7698
          7698 BARRY            2850 MANAGER         7839
          7782 BOEHMER          2695 MANAGER         7839
          7788 PADFIELD         3000 ANALYST         7566
          7839 SCHNEIDER        5500 PRESIDENT
          7844 GASPAROTTO       1500 SALESMAN        7698
          7876 CAVE             1100 CLERK           7788
          7900 CLARKE            950 CLERK           7698
          7902 JAFFAR           3000 ANALYST         7566
          7934 ROBERTSON        1430 CLERK           7782
    14 rows selected.
    SQL> Cheers, APC

  • Sys_connect_by_path_node ? [Can do this in ANSI SQL-99] - Hierarchy Query

    Hi All,
    A slighly more complex connect by problem (that can be done with ANSI SQL-99) looking for an oracle matching output.
    Input Data: (Small example subset)
    RootID | Parent_ID | FreeText
    0 | 0     |
    444 | 555 | ABC1
    555 | 666 | DEF2
    666 | 777 | GHI3
    888 | 0 | JKL4
    Output Wanted: (Small example subset)
    RootID ParentID FreeText          LEVEL (Nesting)
    444 |     555 |               |     1
    444 |     666 |     ABC1          |     2
    444 |     777 |     DEF2-ABC1     |     3
    444 |     888 |     GHI3-DEF2-ABC1      | 4
    444 |     0 |     JKL4-GHI3-DEF2-ABC1 | 5
    Can be easily enough done with ANSI-99 SYNTAX (Not supported in Oracle using a recursive CTE)
    Target platform Oracle 9i
    ANSI-SQL 99 Syntax: (Not Supported on Oracle - but demonstrates the ANSI-SQL 99 compliant way of doing this)
    ;WITH Recurse(RootId, ParentID, FreeText, Level) AS
    (SELECT td.RootID, td.ParentID, '' as FreeText, 1 as Level
    from TEST_DATA td
    where rootid = 444
    union all
    select Recurse.RootID, td2.ParentId, td2.freetext + '-' + recurse.freetext, recurse.level+1 as level
    from TEST_DATA td2
    select * from Recurse;
    The problem: is to generating the freetext component correctly with oracle.
    Can generate the freetext component the wrong way round using SYS_CONNECT_BY_PATH.
    select connect_by_root(td.RootID), td.ParentID,
         CASE when level = 1 then ''
         ELSE
              SYS_CONNECT_BY_PATH(td.freetext, '-')
         END as FreeText, level
    from test_data td
    connect by td.RootID = prior td.ParentID
    which gives:
    RootID ParentID FreeText          LEVEL (Nesting)
    444 | 555     | |     1
    444 | 666 | ABC1 |          2
    444 | 777 | ABC1-DEF2 | 3
    444 | 888 | ABC1-DEF2-GHI3 | 4
    444 | 0 | ABC1-DEF2-GHI3-JKL4 | 5
    The problem is the freetext component is the wrong way round (the root node information always comes first).
    Tried looking at running something like:
    select connect_by_root(td.RootID), td.ParentID,
         CASE when level = 1 then ''
         ELSE
              td.freetext || '-' || FreeText2
         END as FreeText2, level
    from test_data td
    connect by td.RootID = prior td.ParentID
    --> but unfortunatly the aliasing of the column cannot be used to perform this operation [cannot reference the aliased column FreeText2].
    Is there a sys_connect_by_path_node? (The opposite of sys_connect_by_path)
    Returns the path of a column value from node to root,
    with column values separated by char for each row returned by CONNECT BY condition
    Or another way to get to the output required?
    Best Regards,
    D

    Not directly but there is a fairly common workaround using the undocumented REVERSE function.
    Oracle Database 10g Express Edition Release 10.2.0.1.0 - Production
    SQL> SELECT SYS_CONNECT_BY_PATH (ename, '/') enames,
      2         REVERSE (SYS_CONNECT_BY_PATH (REVERSE (ename), '/')) reverse_enames
      3  FROM   emps
      4  START WITH mgr IS NULL
      5  CONNECT BY PRIOR empno = mgr;
    ENAMES                         REVERSE_ENAMES
    /KING                          KING/
    /KING/JONES                    JONES/KING/
    /KING/JONES/SCOTT              SCOTT/JONES/KING/
    /KING/JONES/SCOTT/ADAMS        ADAMS/SCOTT/JONES/KING/
    /KING/JONES/FORD               FORD/JONES/KING/
    /KING/JONES/FORD/SMITH         SMITH/FORD/JONES/KING/
    /KING/BLAKE                    BLAKE/KING/
    /KING/BLAKE/ALLEN              ALLEN/BLAKE/KING/
    /KING/BLAKE/WARD               WARD/BLAKE/KING/
    /KING/BLAKE/MARTIN             MARTIN/BLAKE/KING/
    /KING/BLAKE/TURNER             TURNER/BLAKE/KING/
    /KING/BLAKE/JAMES              JAMES/BLAKE/KING/
    /KING/CLARK                    CLARK/KING/
    /KING/CLARK/MILLER             MILLER/CLARK/KING/
    14 rows selected.
    SQL>

  • 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?

Maybe you are looking for

  • How can my saved highlights be shared on multiple devices

    I am using Dropbox + Adobe Reader on my iPad 1.  I have a lot of highlights however, when I open the PDF on another computer (Windows PDF reader) the highlights are gone. Is there anyway I can save the highlights I've made? Either in the file or in a

  • Inserting text into a field at the current cursor position

    Does anyone know how to insert text into a field at the current cursor position? I would like it to work similar to the Syntax Palette in Forms. I cannot figure out how to retrieve the current cursor position in order to manipulate the text. Any help

  • Hp4580 works on usb but not on wireless

    HP Photosmart C4580 All in one works fine with USB but not with wireless, using HP Pavilion Desktop P7-1108p w/ Windows 7. Tried to reinstall with CD but puter refuses to proceed with run. {Personal Information Removed}

  • Unable to install updates via App Store or Installer.app

    Ever since updating my 2008 Mac Pro from Mountain Lion (+Server.app) to Mavericks (10.9.3+Server.app) about a month ago, I have been unable to install updates on that system in any way, shape, or form.  Fixing permissions did not fix the problem, and

  • Need more than 16bit color depth on Windows XP Mode

    Hi there, i´m testing windows xp mode with some applications, which are not compatible with Windows 7. I want to roll out some clients with Windows 7 and catch all compatibility problems with WindowsXP-Mode. But i´ve got a problem. We need a software