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]

Similar Messages

  • Are Truncate and Trunc SQL ISO ANSI compliance ?

    Somebody has idea of
    which of the statements TRUNCATE and TRUNC are SQL ISO ANSI compliance ?
    is Truncate a function or a statement ?
    Thanks
    Nelson

    perhaps this answer has the potential to add some confusing, but maybe it shows a little problem with ANSI compliance:
    For Oracle a TRUNCATE TABLE is a DDL operation that includes an implicit commit preventing a rollback:
    -- Oracle 11.2.0.1
    SQL> create table t(a number);
    Tabelle wurde erstellt.
    SQL> insert into t(a) values(1);
    1 Zeile wurde erstellt.
    SQL> commit;
    Transaktion mit COMMIT abgeschlossen.
    SQL> truncate table t;
    Tabelle mit TRUNCATE geleert.
    SQL> rollback;
    Transaktion mit ROLLBACK rückgängig gemacht.
    SQL> select * from t;
    Es wurden keine Zeilen ausgewählt
    Sorry about the german sqlplus feedback - but I think the result is clear: the table is empty after the truncate and the data is gone.
    But for MS SQL Server a TRUNCATE can be rolled back:
    -- SQL Server 2008
    drop table t;
    create table t(a int);
    insert into t(a) values(1);
    begin transaction
    truncate table t;
    rollback;
    select * from t;
      a
      1
    Microsoft also defines TRUNCATE as DDL - http://msdn.microsoft.com/en-us/library/ff848799.aspx - but the behavior is quite different. So ANSI compliance does not mean that much (I have absolutly no idea which of the two solutions is more ANSI compliant in this case).
    Regards
    Martin

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

  • SQL recursive query help

    Hi All,
    I have below table
    IT_Terms_First_Date
    IT_Terms_Last_Date
    DI_Debt_Num
    IT_Terms_Seq_Num
    200501
    201101
    1000
    131
    200512
    203412
    1001
    131
    200503
    204209
    1003
    131
    200507
    201001
    1004
    131
    200510
    202710
    1005
    131
    200506
    202412
    10020
    131
    197910
    198310
    257000
    101
    198009
    202909
    298000
    101
    198101
    202908
    298000
    103
    198105
    202910
    298000
    104
    199109
    201309
    578000
    101
    199204
    201110
    600000
    101
    198009
    201010
    298010
    101
    198105
    204010
    298010
    104
    201011
    202909
    298010
    103
    I need to check whether my DI_Debt_Num having Ovelaping or not for each DI_Debt_Num,
    at this moment we are checking each row in loop and usnig function
    exec @Overlap1=[DffMonths] @ITtermsLD,@ITtermsNextFD
    exec @Overlap2=[DffMonths] @ITtermsFD,@ITtermsNextFD
    exec @Overlap3=[DffMonths] @ITtermsFD,@ITtermsNextLD
    if(@Overlap1>0 and (@Overlap2<=0 OR @Overlap3<0))
    BEGIN
    SET @CheckOverlap=1
    END
    here @ITtermsLD is the IT_Terms_Last_Date of the current DI_Debt_Num,@ITtermsNextFD is the IT_Terms_First_Date of the next row. @ITtermsFD is the IT_Terms_First_Date of the current month
    if we consider the 298000 DI_Debt_Num we have 3 IT_Terms_Seq_Num 101,103,104
    in this senario we need to check only the first 2 rows from that itself we can identify it is overlapped ,but when we consider the 298010 we need to check all 3 IT_Terms_Seq_Num 101,103,104 if we consider first two rows 101 & 103 it is not overlapped.Then
    we have to check first row with 3rd row ie 104 and it is overlapped.We are checking the overlap senario for DI_Debt_Num having multipple IT_Terms_Seq_Num rows
    Some situation first row may not be overlapped with other rows .Then we have to check the 2nd row with the next rows in the same way we are doing for first row
    My aim is to covert this looping method to a select query to improve my query performance
    Thanks in advance
    Roshan

    Please post DDL, so that people do not have to guess what the keys, constraints, Declarative Referential Integrity, data types, etc. in your schema are. Learn how to follow ISO-11179 data element naming conventions and formatting rules. You have no idea,
    do you? Temporal data should use ISO-8601 formats. You failed again! I will guess that your dates are months. Code should be in Standard SQL as much as possible and not local dialect. 
    This is minimal polite behavior on SQL forums. 
    >> I have below table <<
    This is not a table! Where is the DDL?  This picture has no name. Not even a name!! There is no “seq_nbr” in RDBMS; it has to be a “<something in particular>_seq” and there are no duplicates in a sequence. 
    My guess is that each di_debt_nbr has a sequence within its range. I will call it the “foobar_seq” for lack of a name. 
    My next guess is that your dates are really months and you do not know about using a report period table. This idiom gives a name to a range of dates that is common to the entire enterprise. 
    CREATE TABLE Something_Report_Periods
    (something_report_name CHAR(10) NOT NULL PRIMARY KEY
       CHECK (something_report_name LIKE <pattern>), 
     something_report_start_date DATE NOT NULL, 
     something_report_end_date DATE NOT NULL, 
      CONSTRAINT date_ordering
        CHECK (something_report_start_date <= something_report_end_date), 
    etc);
    These report periods can overlap or have gaps. I like the MySQL convention of using double zeroes for months and years, That is 'yyyy-mm-00' for a month within a year and 'yyyy-00-00' for the whole year. The advantages are that it will sort with the ISO-8601
    data format required by Standard SQL and it is language independent. The pattern for validation is '[12][0-9][0-9][0-9]-00-00' and '[12][0-9][0-9][0-9]-[01][0-9]-00'
    Here is another guess at what you want, if you knew what a table is: 
    CREATE TABLE DI_Debts
    (it_terms_first_date CHAR(10) NOT NULL
       REFERENCES Report_Period (month_name), 
     it_terms_last_date CHAR(10) NOT NULL
       REFERENCES Report_Period (month_name), 
     CHECK (it_terms_first_date <= it_terms_last_date), 
     di_debt_nbr INTEGER NOT NULL, 
     foobar_seq INTEGER NOT NULL, 
     PRIMARY KEY (di_debt_nbr, foobar_seq));
    INSERT INTO DI_Debts
    VALUES
    ('2005-01-00', '2011-01-00', 1000, 1), 
    ('2005-12-00', '2034-12-00', 1001, 1), 
    ('2005-03-00', '2042-09-00', 1003, 1), 
    ('2005-07-00', '2010-01-00', 1004, 1), 
    ('2005-10-00', '2027-10-00', 1005, 1), 
    ('2005-06-00', '2024-12-00', 100201, 1), 
    ('1979-10-00', '1983-10-00', 257000, 1), 
    ('1980-09-00', '2029-09-00', 2980001, 1), 
    ('1981-01-00', '2029-08-00', 298000, 1), 
    ('1981-05-00', '2029-10-00', 298000, 2), 
    ('1991-09-00', '2013-09-00', 578000, 1), 
    ('1992-04-00', '2011-10-00', 600000, 1), 
    ('1980-09-00', '2010-10-00', 298010, 1), 
    ('1981-05-00', '2040-10-00', 298010, 2), 
    ('2010-11-00', '2029-09-00', 298010, 3);
    I need to check whether my DI_Debt_nbr are overlapping or not for each DI_Debt_nbr, 
    >> at this moment we are checking each row in loop and using function 
    exec @Overlap1=[DffMonths] @IttermsLD, @ITtermsNextFD;
    exec @Overlap2=[DffMonths] @IttermsFD, @ITtermsNextFD;
    exec @Overlap3=[DffMonths] @IttermsFD, @ITtermsNextLD; <<
    And you were too rude to post the code for these functions! You write SQL with assembly language flags! We do not do that!  We also would use a CASE expression, and not IF-THEN control flow in SQL.  
    Did you know that ANSI/ISO Standard SQL has a temporal <overlaps predicate>? Notice the code to handle NULLs and the ISO half-open interval model. 
    (start_date_1 > start_date_2 
     AND NOT (start_date_1 >= end_date_2 
                AND end_date_1 >= end_date_2)) 
    OR (start_date_2 > start_date_1 
        AND NOT (start_date_2 >= end_date_1 
                 AND end_date_2 >= end_date_1)) 
    OR (start_date_1 = start_date_2 
        AND (end_date_1 <> end_date_2 OR end_date_1 = end_date_2)) 
    I tend to prefer the use of a calendar table. NULLs return an empty set, as above. 
    EXISTS 
    ((SELECT cal_date FROM Calendar 
       WHERE cal_date BETWEEN start_date_1 AND end_date_1)
     INTERSECT
     (SELECT cal_date FROM Calendar 
       WHERE cal_date BETWEEN start_date_2 AND end_date_2))
    --CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
    in Sets / Trees and Hierarchies in SQL

  • 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

  • ANSI SQL JOIN

    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
    MM

    SELECT 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 )

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

  • 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

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

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

  • Oracle SQL Select query takes long time than expected.

    Hi,
    I am facing a problem in SQL select query statement. There is a long time taken in select query from the Database.
    The query is as follows.
    select /*+rule */ f1.id,f1.fdn,p1.attr_name,p1.attr_value from fdnmappingtable f1,parametertable p1 where p1.id = f1.id and ((f1.object_type ='ne_sub_type.780' )) and ( (f1.id in(select id from fdnmappingtable where fdn like '0=#1#/14=#S0058-3#/17=#S0058-3#/18=#1#/780=#5#%')))order by f1.id asc
    This query is taking more than 4 seconds to get the results in a system where the DB is running for more than 1 month.
    The same query is taking very few milliseconds (50-100ms) in a system where the DB is freshly installed and the data in the tables are same in both the systems.
    Kindly advice what is going wrong??
    Regards,
    Purushotham

    SQL> @/alcatel/omc1/data/query.sql
    2 ;
    9 rows selected.
    Execution Plan
    Plan hash value: 3745571015
    | Id | Operation | Name |
    | 0 | SELECT STATEMENT | |
    | 1 | SORT ORDER BY | |
    | 2 | NESTED LOOPS | |
    | 3 | NESTED LOOPS | |
    | 4 | TABLE ACCESS FULL | PARAMETERTABLE |
    |* 5 | TABLE ACCESS BY INDEX ROWID| FDNMAPPINGTABLE |
    |* 6 | INDEX UNIQUE SCAN | PRIMARY_KY_FDNMAPPINGTABLE |
    |* 7 | TABLE ACCESS BY INDEX ROWID | FDNMAPPINGTABLE |
    |* 8 | INDEX UNIQUE SCAN | PRIMARY_KY_FDNMAPPINGTABLE |
    Predicate Information (identified by operation id):
    5 - filter("F1"."OBJECT_TYPE"='ne_sub_type.780')
    6 - access("P1"."ID"="F1"."ID")
    7 - filter("FDN" LIKE '0=#1#/14=#S0058-3#/17=#S0058-3#/18=#1#/780=#5#
    8 - access("F1"."ID"="ID")
    Note
    - rule based optimizer used (consider using cbo)
    Statistics
    0 recursive calls
    0 db block gets
    0 consistent gets
    0 physical reads
    0 redo size
    0 bytes sent via SQL*Net to client
    0 bytes received via SQL*Net from client
    0 SQL*Net roundtrips to/from client
    0 sorts (memory)
    0 sorts (disk)
    9 rows processed
    SQL>

  • Sql select query problem

    hi friends,
    i've a view called "risk_efforts" with fields user_id,user_name,wknd_dt,week_day,prod_efforts,unprod_efforts.
    Name Type
    ROW_ID NUMBER
    USER_ID VARCHAR2(14)
    USER_NAME VARCHAR2(50)
    WKND_DT VARCHAR2(8)
    WEEK_DAY VARCHAR2(250)
    PROD_EFFORTS NUMBER
    UNPROD_EFFORTS NUMBER
    data is like this:
    when there is some data in prod_efforts, unprod_efforts will be null
    when there is some data in unprod_efforts, prod_efforts will be null
    for example:
    USER_ID     USER_NAME     WKND_DT     WEEK_DAY     PROD_EFFORTS     UNPROD_EFFORTS
    G666999     GTest     20100403     TUE     null 3
    G666999     GTest     20100403     TUE     14     null
    now i want to combine these 2 rows into 1 row i.e o/p should be like this
    USER_ID     USER_NAME     WKND_DT     WEEK_DAY     PROD_EFFORTS     UNPROD_EFFORTS
    G666999     GTest     20100403     TUE     14 3
    i've tried all combinations but couldn't get the query. Please help me with the exact SQL select query.
    thanks,
    Girish

    Welcome to the forum.
    First read this:
    Urgency in online postings
    Secondly, it's always helpful to provide the following:
    1. Oracle version (SELECT * FROM V$VERSION)
    2. Sample data in the form of CREATE / INSERT statements.
    3. Expected output
    4. Explanation of expected output (A.K.A. "business logic")
    5. Use \ tags for #2 and #3. See FAQ (Link on top right side) for details.
    You have provided #3 and #4. However with no usable form of sample data forum members will often not respond as quickly as they could if you provided #2.
    I'm just wagering a guess here but what about this:SELECT ROW_ID
    , USER_ID
    , WKND_DT
    , WEEK_DAY
    , MAX(PROD_EFFORTS) AS PROD_EFFORTS
    , MAX(UNPROD_EFFORTS) AS UNPROD_EFFORTS
    FROM RISK_EFFORTS
    GROUP BY ROW_ID
    , USER_ID
    , WKND_DT
    , WEEK_DAY                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • How to capture all the rows returned from a sql select query in CPO

    Hi,
      I am executing an sql select query which returns multiple rows. I need to capture the values of each row to specific variables. How do I proceed.
    Thanks,
    Swati

    The select activities  ("Select from Oracle," Select from SQL Server," etc.) against database already return tables.  Use one of the database adapters to do your select, and it will already be in a table form.  Just put your query in the select and identify the columns in your result table. The online help or the database adapter guides in the product documentation can help.

  • Reg: SQL select Query in BPEL process flow

    <p>
    Hi,
    I am suppose to execute a SQL select query (in BPEL Process flow) as mention below in JDeveloper using Database adapter.
    </p>
    <p>
    SELECT LENGTH, WIDTH, HEIGHT, WEIGHT,
    </p>
    <p>
    LENGTH*WIDTH* HEIGHT AS ITEM_CUBE
    </p>
    <p>
    FROM CUBE
    </p>
    <p>
    WHERE ITEM= &lt;xyz&gt;
    </p>
    <p>
    AND OBJECT= (SELECT CASE_NAME FROM CUBE_SUPPLIER WHERE ITEM=&lt;xyz&gt; AND SUPP_IND = &lsquo;Y')
    <strong>Now my question is:
    1.</strong> What does this "*" refer to in the query and how can I retrieve the value of LENGTH*WIDTH* HEIGHT from the query where LENGTH,WIDTH and HEIGHT are the individual field in the table.
    2.What does this " AS" refer to? If " ITEM_CUBE " is the alies for the table name "ITEM" to retrieve the value, then query shoud be evaluated as
    </p>
    <p>
    SELECT LENGTH, WIDTH, HEIGHT, WEIGHT,
    </p>
    <p>
    LENGTH*WIDTH* HEIGHT AS ITEM_CUBE
    </p>
    <p>
    FROM CUBE
    </p>
    <p>
    WHERE <strong>ITEM_CUBE.ITEM</strong>= &lt;xyz&gt;
    </p>
    <p>
    AND <strong>ITEM_CUBE.OBJECT</strong>= (SELECT CASE_NAME FROM CUBE_SUPPLIER WHERE ITEM=&lt;xyz&gt; AND SUPP_IND = &lsquo;Y')
    Is my assumption correct?
    Please suggest asap.
    Thanks...
    </p>
    <p>
    </p>

    Hi
    Thank for your reply!
    I have a nested select query which performs on two different table as shown below:
    <p>
    SELECT LENGTH, WIDTH, HEIGHT, WEIGHT,
    </p>
    <p>
    LENGTH*WIDTH* HEIGHT AS ITEM_CUBE
    </p>
    <p>
    FROM CUBE
    </p>
    <p>
    WHERE ITEM= &lt;abc&gt;
    </p>
    <p>
    AND OBJECT= (SELECT NAME FROM SUPPLIER WHERE ITEM=&lt;Item&gt; AND SUPP_IND = &lsquo;Y')
    I am using DB adapter of Oracle JDeveloper in BPEL process flow, where I can able to select only one master table in DB adapter say SUPPLIER and its attributes at a time.But as per my requirment I need to select both the table (CUBE and SUPPLIER) in a single adapter to execute my query.
    It can be achievable by using two DB adapter , One to execute the nested query and another to execute the main qyery considering value of nested query as a parameter.But I want to achieve it by using a single one.
    Am I correct with my concept?
    Please suggest how to get it ?
    </p>
    Edited by: user10259700 on Oct 23, 2008 12:17 AM

  • 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

Maybe you are looking for

  • Keep your phone secure!

    The virus and worm threat has reached the mobile world, and like on your computer there are a few things you can do to prevent an attack: How can malware get on my phone? Via SMS, as an internet link Via Email, as an attachment or a link Via Bluetoot

  • XHTML page with current PHP form - client wants Coldfusion integration...

    I have never worked with  Coldfusion before and I have no idea what it involves. The form is setup  with PHP right now, however, the client uses Coldfusion and would  prefer the form to be set up to integrate with it. I dont even know where to start!

  • Enhance Infotype 2011

    Hi. Is there any way to enhance infotype 2011?? I'm going through pm01 transaction but i got an error message?? Anybody can help?

  • HT5071 Can I distribute the book for free to only certain people?

    I like to create a textbook for my class and want only my students can download for free. Can I do this?

  • Latest nightly sdk causes Java Heap error during build

    The latest nightly sdk 4.0.0.13210 causes out of memory error in Flash Builder during a clean build.  However the prior nightly build (4.0.0.13175) works fine.  I'm using build 262635 of Flash Builder.  What changed in the latest nightly that could c