Let us discussion "non recursive with clause" usage

I think there are 3 "non recursive with clause" usage.
My question is do you know more "non recursive with clause" usage ?

Another option is to use it to materialize remote data on the fly. Especially in combination with the materialize hint.
I think I used this tecnique once, but can't find the proper example anymore. Very simplified it could looked like this:
with fetchData as (Select /*+materialize */ * from myremoteTable@databaselink where status = 'CURRENT')
select *
from fetchdata r
full outer join localData l on r.id = r.id
where l.status = 'CURRENT'
;From 11g onwards: use the with clause to create better column names in larger select from dual combinations.
Not sure with that results in a suitable use case.
So instead of
with orders as
(select 1 id , 173 order#, 'John' customer, 'America' region from dual union all
  select 2 id , 170 order#, 'Paul' customer, 'UK' region from dual union all
  select 3 id , 240 order#, 'Hans' customer, 'Europe' region from dual union all
  select 4 id , 241 order#, 'Francois' customer, 'Europe' region from dual )
select * from orders;you can now write
with
orders (id, order#, customer,region) as
(select 1 , 173 , 'John' , 'America' from dual union all
  select 2 , 170 , 'Paul' , 'UK' from dual union all
  select 3 , 240 , 'Hans' , 'Europe' from dual union all
  select 4 , 241 , 'Francois' , 'Europe' from dual )
select * from orders;THis makes it a little easier to create tase data useing some excel sheet I guess.

Similar Messages

  • Recursive with clause

    Hi All,
    I am using oracle 11.2.0.4
    I m using this for learning purpose
    Below is my table and insert statement
    CREATE TABLE NUMBERS(NUM NUMBER);
    INSERT INTO NUMBERS VALUES(1);
    INSERT INTO NUMBERS VALUES(2);
    INSERT INTO NUMBERS VALUES(3);
    INSERT INTO NUMBERS VALUES(4);
    WITH RSFC(ITERATION,RUNNING_FACTORIAL) AS
    (SELECT NUM AS ITERATION,
    1 AS RUNNING_FACTORIAL
    FROM NUMBERS
    WHERE NUM=1
    UNION ALL
    SELECT R.ITERATION+1,
            R.RUNNING_FACTORIAL * B.NUM
            FROM RSFC R INNER JOIN NUMBERS B
            ON (R.ITERATION+1) + B.NUM    
            SELECT ITERATION,RUNNING_FACTORIAL
            FROM RSFC
    I am learning recursive with clause
    when I am trying to execute the query I am getting
    ORA-00920 : invalid realtional operator
    what is wrong in this query,please help me
    Thanks and Regrds,
    Subho

    Hi,
    2937991 wrote:
    Hi All,
    I am using oracle 11.2.0.4
    I m using this for learning purpose
    Below is my table and insert statement
    CREATE TABLE NUMBERS(NUM NUMBER);
    INSERT INTO NUMBERS VALUES(1);
    INSERT INTO NUMBERS VALUES(2);
    INSERT INTO NUMBERS VALUES(3);
    INSERT INTO NUMBERS VALUES(4);
    WITH RSFC(ITERATION,RUNNING_FACTORIAL) AS
    (SELECT NUM AS ITERATION,
    1 AS RUNNING_FACTORIAL
    FROM NUMBERS
    WHERE NUM=1
    UNION ALL
    SELECT R.ITERATION+1,
            R.RUNNING_FACTORIAL * B.NUM
            FROM RSFC R INNER JOIN NUMBERS B
            ON (R.ITERATION+1) + B.NUM   
            SELECT ITERATION,RUNNING_FACTORIAL
            FROM RSFC
    I am learning recursive with clause
    when I am trying to execute the query I am getting
    ORA-00920 : invalid realtional operator
    what is wrong in this query,please help me
    Thanks and Regrds,
    Subho
    The error actually has nothing to do with the WITH clause.
    Join conditions (that is, the conditions following the ON keyword) must be expressions that evaluate to TRUE or FALSE.  The join condition you posted, however
    (R.ITERATION+1) + B.NUM   
    evaluates to a NUMBER.  The following would be a valid join condition:
    (R.ITERATION+1) = B.NUM  
    but I have no idea if that's what you wanted or not.

  • Since Oracle11gR2,"recursive with clause" is supported.

    http://download.oracle.com/docs/cd/E11882_01/server.112/e16579/aggreg.htm#i1007241
    <i>Note that Oracle Database does not support recursive use of the WITH clause</i>
    This is wrong.
    Since Oracle11gR2 recursive with clause is supported.
    Please fix this wrong statement of document.
    I like recursive with clause 8-)

    I'm the writer for this doc, and you are correct. This sentence was not removed when the 11.2 doc was updated, and it should have been. I have removed it for the 12g doc.

  • 'CONNECT BY PRIOR..START WITH'  clause  Usage

    Hi All,
    Could you please let me know the usage of 'connect by prior...start with' clause.
    I only know that it helps for hierarchial retrival,but not aware of details.
    Can someone provide the use with example for the same.
    On searching on the net,I have seen numerous examples but none of them could explain it properly and everywhere the same SCOTT/TIGER schemas EMP and MGR table's example is given which is not enough explanatory.
    Thanks in advance...
    Aashish S.

    suppose u need to get all employees in a company in a hirerchical manner
    ie presdent then mgrs
    then employeess reporting to them
    this can be done using connect by prior and start by
    select empname from emp
    connect by prior empno=mgrno
    start with mgrno is null

  • With clause usage in cursor

    is it possible to use with clause in cursor declaration.
    see the below simple example.
    it gives error.
    declare
    cursor t is
    (with hi as
    (select * from pepole )
    select distinct hi.id from hi where id =55);
    begin
    null;
    end;

    Remove the outer set of parenthesis.
    declare
    cursor t is
    with hi as
    (select * from emp )
    select distinct sal from hi;
    begin
    null;
    end;

  • To use "analytic function" at "recursive with clause"

    http://docs.oracle.com/cd/E11882_01/server.112/e26088/statements_10002.htm#i2077142
    The recursive member cannot contain any of the following elements:
    ・An aggregate function. However, analytic functions are permitted in the select list.
    OK I will use analytic function at The recursive member :-)
    SQL> select * from v$version;
    BANNER
    Oracle Database 11g Release 11.2.0.1.0 - Production
    PL/SQL Release 11.2.0.1.0 - Production
    CORE    11.2.0.1.0      Production
    TNS for 32-bit Windows: Version 11.2.0.1.0 - Production
    NLSRTL Version 11.2.0.1.0 - Production
    SQL> with rec(Val,TotalRecCnt) as(
      2  select 1,1 from dual
      3  union all
      4  select Val+1,count(*) over()
      5    from rec
      6   where Val+1 <= 5)
      7  select * from rec;
    select * from rec
    ERROR at line 7:
    ORA-32486: unsupported operation in recursive branch of recursive WITH clauseWhy ORA-32486 happen ?:|

    Hi Aketi,
    It works in 11.2.0.2, so it is probably a bug:
    select * from v$version
    BANNER                                                                          
    Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production    
    PL/SQL Release 11.2.0.2.0 - Production                                          
    CORE     11.2.0.2.0     Production                                                        
    TNS for IBM/AIX RISC System/6000: Version 11.2.0.2.0 - Production               
    NLSRTL Version 11.2.0.2.0 - Production                                          
    with rec(Val,TotalRecCnt) as(
    select 1,1 from dual
    union all
    select Val+1,count(*) over()
    from rec
    where Val+1 <= 5)
    select * from rec
    VAL                    TOTALRECCNT           
    1                      1                     
    2                      1                     
    3                      1                     
    4                      1                     
    5                      1                      Regards,
    Bob

  • ORA-01790 from 11gR2 Recursive with clause

    I guess below result is bug.
    SQL> select * from v$version;
    BANNER
    Oracle Database 11g Release 11.2.0.1.0 - Production
    PL/SQL Release 11.2.0.1.0 - Production
    CORE     11.2.0.1.0     Production
    TNS for 32-bit Windows: Version 11.2.0.1.0 - Production
    NLSRTL Version 11.2.0.1.0 - Production
    SQL> with tmp(day1) as(select date '2009-06-01' from dual),
      2  rec(day1) as(
      3  select day1 from tmp
      4  union all
      5  select add_months(day1,1)
      6    from rec
      7   where add_months(day1,1) < date '2010-05-05')
      8  select * from rec;
    select add_months(day1,1)
    行5でエラーが発生しました。:
    ORA-01790: 式には対応する式と同じデータ型を持つ必要がありますI suppose above two expression is same data type,because below SQL is executable.
    with tmp(day1) as(select date '2009-06-01' from dual)
    select day1 from tmp
    union all
    select add_months(day1,1) from tmp;
    day1
    09-06-01
    09-07-01

    Well strange error I got for the SQLs you have given :p
    with tmp(day1) as(select date '2009-06-01' from dual),
        rec(day1) as(
        select day1 from tmp
        union all
        select add_months(day1,1)
          from rec
         where add_months(day1,1) < date '2010-05-05')
        select * from rec;
    ORA-32033: unsupported column aliasing
    with tmp(day1) as(select date '2009-06-01' from dual)
    select day1 from tmp
    union all
    select add_months(day1,1) from tmp;
    ORA-32033: unsupported column aliasing
    SELECT *
    FROM V$VERSION;
    BANNER
    Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - Production
    PL/SQL Release 11.1.0.7.0 - Production
    CORE 11.1.0.7.0 Production
    TNS for Linux: Version 11.1.0.7.0 - Production
    NLSRTL Version 11.1.0.7.0 - Production*009*
    Edited by: 009 on Apr 7, 2010 9:16 PM

  • ORA-32031: illegal reference of a query name in WITH clause

    Oracle tutorial : http://www.oracle.com/technology/pub/articles/hartley-recursive.html#4
    When Executing this Query 6: Using a Recursive WITH Clause
    WITH C (CNO, PCNO, CNAME) AS
    (SELECT CNO, PCNO, CNAME -- initialization subquery
    FROM COURSEX
    WHERE CNO = 'C22' -- seed
    UNION ALL
    SELECT X.CNO, X.PCNO, X.CNAME -- recursive subquery
    FROM C, COURSEX X
    WHERE C.PCNO = X.CNO)
    SELECT CNO, PCNO, CNAME
    FROM C;
    Error: ORA-32031: illegal reference of a query name in WITH clause
    kindly suggest what need to do in case of recursion using subquery

    SCOTT@orcl> ed
    Wrote file afiedt.buf
      1  with c as
      2  (
      3  select empno,ename from emp
      4  where deptno=20
      5  union all
      6  select c.empno,c.ename from emp c
      7  where c.deptno=30
      8  )
      9* select * from c
    SCOTT@orcl> /
         EMPNO ENAME
          7566 xx
          7788 xx
          7876 xx
          7902 xx
          7499 xx
          7521 xx
          7654 xx
          7698 xx
          7844 xx
          7900 xx
    10 rows selected.
    SCOTT@orcl> ed
    Wrote file afiedt.buf
      1  with emp as
      2  (
      3  select empno,ename from emp
      4  where deptno=20
      5  union all
      6  select c.empno,c.ename from emp c
      7  where c.deptno=30
      8  )
      9* select * from emp
    SCOTT@orcl> /
    select empno,ename from emp
    ERROR at line 3:
    ORA-32031: illegal reference of a query name in WITH clause
    SCOTT@orcl>You can not use the same table name alongwith WITH clause's cursor name. See as above if i says with C as... its works; but if i says with emp as... it returned ora-32031, because it is the name of table.
    HTH
    Girish Sharma

  • Issue in use of "WITH CLAUSE"

    My DB version is 10.2.0
    One of my query takes long time for execution and here is the Old Query,
    SELECT HD.DATUM DATUM, HA2.GELDEINGAENGE_INSG-NVL(HA3.VERWERTUNGSERLOESE,0)
      GELDEINGANG, HA3.VERWERTUNGSERLOESE
    FROM
    ( SELECT DISTINCT(TO_CHAR(ERFASSDATUM,'YYYY/MM')) DATUM
      FROM TRANS_HIST H1 ,
        (SELECT BUCHUNGSGRUPPE, LFDNR, SICHERHEITBEZUG
        FROM BUCHUNGSSCHL
        WHERE STORNOMM=0) B1
      WHERE H1.ERFASSDATUM >=TO_DATE('01.10'||TO_CHAR(ADD_MONTHS(SYSDATE,-9),'YYYY')||' 00.00.00','DD.MM.YYYY HH24:MI:SS')
      AND H1.BUCHUNGSGRUPPE = B1.BUCHUNGSGRUPPE AND H1.LFDNR = B1.LFDNR
      AND (H1.BUCHUNGSGRUPPE = '8888' OR ( H1.BUCHUNGSGRUPPE > 5999 AND H1.BUCHUNGSGRUPPE < 7100 AND B1.SICHERHEITBEZUG = 1)) ) HD,
      (SELECT TO_CHAR(ERFASSDATUM,'YYYY/MM') DATUM, SUM(BETRAG) GELDEINGAENGE_INSG
      FROM TRANS_HIST H2,
      (SELECT F.GLAEUBIGERNR,F.FORDNR,F.FORDERGNR,A.MAHN_NUM
      FROM FRD_ACCT F,
      (SELECT * FROM ANS_PRCH WHERE RANGMM=1) A
      WHERE F.GLAEUBIGERNR=A.GLAEUBIGERNR (+) AND F.FORDNR=A.FORDNR(+)
      AND F.FORDERGNR=A.FORDERGNR(+) AND NVL(F.INDIVIDUALFLAG,0)=0 ) F1
      WHERE ( (F1.GLAEUBIGERNR= H2.GLAEUBIGERNR AND F1.FORDNR=H2.FORDNR AND F1.FORDERGNR=H2.FORDERGNR) OR
      F1.MAHN_NUM = H2.MAHN_NUM) AND H2.BUCHUNGSGRUPPE = '8888' AND
      H2.ERFASSDATUM >= TO_DATE('01.10'||TO_CHAR(ADD_MONTHS(SYSDATE,-9),'YYYY')||' 00.00.00','DD.MM.YYYY HH24:MI:SS')
      GROUP BY TO_CHAR(ERFASSDATUM,'YYYY/MM') ) HA2,
      (SELECT TO_CHAR(ERFASSDATUM,'YYYY/MM') DATUM, SUM(BETRAG) VERWERTUNGSERLOESE
       FROM TRANS_HIST H3, (SELECT BUCHUNGSGRUPPE, LFDNR,
      SICHERHEITBEZUG, NACHMIETVERTRAGE
      FROM BUCHUNGSSCHL
      WHERE STORNOMM=0) B3,
      (SELECT F.GLAEUBIGERNR,F.FORDNR,F.FORDERGNR,A.MAHN_NUM
      FROM FRD_ACCT F,
      (SELECT * FROM ANS_PRCH WHERE RANGMM=1) A
      WHERE F.GLAEUBIGERNR= A.GLAEUBIGERNR (+) AND F.FORDNR=A.FORDNR(+)
      AND F.FORDERGNR=A.FORDERGNR(+) AND NVL(F.INDIVIDUALFLAG,0)=0 ) F2
      WHERE ( (F2.GLAEUBIGERNR=H3.GLAEUBIGERNR AND F2.FORDNR=H3.FORDNR AND F2.FORDERGNR=H3.FORDERGNR)
      OR F2.MAHN_NUM = H3.MAHN_NUM)
      AND H3.ERFASSDATUM >=TO_DATE('01.10'||TO_CHAR(ADD_MONTHS(SYSDATE,-9),'YYYY')||' 00.00.00','DD.MM.YYYY HH24:MI:SS')
      AND H3.BUCHUNGSGRUPPE = B3.BUCHUNGSGRUPPE AND
      H3.LFDNR = B3.LFDNR AND H3.BUCHUNGSGRUPPE > 5999
      AND H3.BUCHUNGSGRUPPE < 7100 AND (B3.SICHERHEITBEZUG = 1 OR B3.NACHMIETVERTRAGE =1)
      GROUP BY TO_CHAR(ERFASSDATUM,'YYYY/MM') ) HA3
      WHERE HD.DATUM=HA2.DATUM (+)
      AND HD.DATUM=HA3.DATUM (+)
      ORDER BY DATUM ASC
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        1      0.22       0.22          0          0          0           0
    Execute      1      0.00       0.00          0          0          0           0
    Fetch        1    469.61    1448.30    2874498    3017355          1           9
    total        3    469.83    1448.53    2874498    3017355          1           9
    Misses in library cache during parse: 1
    Optimizer mode: ALL_ROWS
    Parsing user id: 62     (recursive depth: 1)
    Rows     Row Source Operation
          9  SORT ORDER BY (cr=3017355 pr=2874498 pw=0 time=1448309418 us)
          9   HASH JOIN RIGHT OUTER (cr=3017355 pr=2874498 pw=0 time=1448309191 us)
          9    VIEW  (cr=1228085 pr=1175604 pw=0 time=906871801 us)
          9     HASH GROUP BY (cr=1228085 pr=1175604 pw=0 time=906871785 us)
       1559      CONCATENATION  (cr=1228085 pr=1175604 pw=0 time=564453620 us)
        233       HASH JOIN  (cr=614043 pr=589377 pw=0 time=562088377 us)
         94        TABLE ACCESS FULL BUCHUNGSSCHL (cr=29 pr=0 pw=0 time=505 us)
    254136        HASH JOIN  (cr=614014 pr=589377 pw=0 time=509476999 us)
    497464         TABLE ACCESS FULL TRANS_HIST (cr=586339 pr=562603 pw=0 time=65783878 us)
    737515         HASH JOIN RIGHT OUTER (cr=27675 pr=26774 pw=0 time=18577731 us)
    372656          TABLE ACCESS FULL ANS_PRCH (cr=6346 pr=5910 pw=0 time=408778 us)
    737515          TABLE ACCESS FULL FRD_ACCT (cr=21329 pr=20864 pw=0 time=2254657 us)
       1326       HASH JOIN  (cr=614042 pr=586227 pw=0 time=520726941 us)
         94        TABLE ACCESS FULL BUCHUNGSSCHL (cr=29 pr=0 pw=0 time=641 us)
    221360        FILTER  (cr=614013 pr=586227 pw=0 time=372791872 us)
    221360         HASH JOIN OUTER (cr=614013 pr=586227 pw=0 time=372570499 us)
    221360          HASH JOIN  (cr=607668 pr=580286 pw=0 time=368077766 us)
    243053           TABLE ACCESS FULL TRANS_HIST (cr=586339 pr=563978 pw=0 time=1425434011 us)
    737515           TABLE ACCESS FULL FRD_ACCT (cr=21329 pr=16308 pw=0 time=8859226 us)
    372656          TABLE ACCESS FULL ANS_PRCH (cr=6345 pr=5941 pw=0 time=1872464 us)
          9    HASH JOIN OUTER (cr=1789270 pr=1698894 pw=0 time=541436637 us)
          9     VIEW  (cr=586667 pr=562439 pw=0 time=213337882 us)
          9      HASH UNIQUE (cr=586667 pr=562439 pw=0 time=213337873 us)
    748717       HASH JOIN  (cr=586667 pr=562439 pw=0 time=104432018 us)
        830        TABLE ACCESS FULL BUCHUNGSSCHL (cr=29 pr=0 pw=0 time=1042 us)
    1241936        TABLE ACCESS FULL TRANS_HIST (cr=586638 pr=562439 pw=0 time=339666777 us)
          9     VIEW  (cr=1202603 pr=1136455 pw=0 time=328097826 us)
          9      HASH GROUP BY (cr=1202603 pr=1136455 pw=0 time=328097809 us)
    695373       CONCATENATION  (cr=1202603 pr=1136455 pw=0 time=324453471 us)
          0        HASH JOIN  (cr=587003 pr=557994 pw=0 time=167168982 us)
    744472         TABLE ACCESS FULL TRANS_HIST (cr=587003 pr=557994 pw=0 time=30622271 us)
          0         HASH JOIN RIGHT OUTER (cr=0 pr=0 pw=0 time=0 us)
          0          TABLE ACCESS FULL ANS_PRCH (cr=0 pr=0 pw=0 time=0 us)
          0          TABLE ACCESS FULL FRD_ACCT (cr=0 pr=0 pw=0 time=0 us)
    695373        FILTER  (cr=615600 pr=578461 pw=0 time=157284464 us)
    695373         HASH JOIN OUTER (cr=615600 pr=578461 pw=0 time=156589072 us)
    695373          HASH JOIN  (cr=609255 pr=572518 pw=0 time=150571393 us)
    744472           TABLE ACCESS FULL TRANS_HIST (cr=587926 pr=556115 pw=0 time=31820718 us)
    737515           TABLE ACCESS FULL FRD_ACCT (cr=21329 pr=16403 pw=0 time=3696334 us)
    372656          TABLE ACCESS FULL ANS_PRCH (cr=6345 pr=5943 pw=0 time=391928 us)I tried fine tuning the query using "With Clause" but landed up with oracle error, which prevents me from using with clause inside a paranthesis.
    SELECT HD.DATUM DATUM, HA2.GELDEINGAENGE_INSG-NVL(HA3.VERWERTUNGSERLOESE,0)
      GELDEINGANG, HA3.VERWERTUNGSERLOESE
    FROM
    ( WITH HIST_VIEW AS (SELECT GLAEUBIGERNR,FORDNR,FORDERGNR,MAHN_NUM,BUCHUNGSGRUPPE,LFDNR,STORNOMM,ERFASSDATUM,BETRAG
                         FROM TRANS_HIST H
                         WHERE ERFASSDATUM >=TO_DATE('01.10'||TO_CHAR(ADD_MONTHS(SYSDATE,-9),'YYYY')||' 00.00.00','DD.MM.YYYY HH24:MI:SS')
                         AND  (H.BUCHUNGSGRUPPE = '8888' OR ( H.BUCHUNGSGRUPPE > 5999 AND H.BUCHUNGSGRUPPE < 7100))),
           FORD_VIEW AS (SELECT F.GLAEUBIGERNR,F.FORDNR,F.FORDERGNR,A.MAHN_NUM
                         FROM FRD_ACCT F,ANS_PRCH A
                         WHERE F.GLAEUBIGERNR=A.GLAEUBIGERNR(+) AND F.FORDNR=A.FORDNR(+)
                         AND F.FORDERGNR=A.FORDERGNR(+) AND NVL(F.INDIVIDUALFLAG,0)=0 AND  A.RANGMM=1)
    (SELECT DISTINCT(TO_CHAR(ERFASSDATUM,'YYYY/MM')) DATUM
      FROM HIST_VIEW H1 ,BUCHUNGSSCHL B1
      WHERE B1.STORNOMM=0  AND H1.BUCHUNGSGRUPPE = B1.BUCHUNGSGRUPPE AND H1.LFDNR = B1.LFDNR
      AND (H1.BUCHUNGSGRUPPE = '8888' OR (H1.BUCHUNGSGRUPPE > 5999 AND H1.BUCHUNGSGRUPPE < 7100 AND B1.SICHERHEITBEZUG = 1))) HD,
    (SELECT TO_CHAR(ERFASSDATUM,'YYYY/MM') DATUM, SUM(BETRAG) GELDEINGAENGE_INSG
      FROM HIST_VIEW H2,FORD_VIEW F1
      WHERE ((F1.GLAEUBIGERNR= H2.GLAEUBIGERNR AND F1.FORDNR=H2.FORDNR AND F1.FORDERGNR=H2.FORDERGNR) OR
      F1.MAHN_NUM = H2.MAHN_NUM) AND H2.BUCHUNGSGRUPPE = '8888'
      GROUP BY TO_CHAR(ERFASSDATUM,'YYYY/MM') ) HA2,
    (SELECT TO_CHAR(ERFASSDATUM,'YYYY/MM') DATUM, SUM(BETRAG) VERWERTUNGSERLOESE
      FROM HIST_VIEW H3, BUCHUNGSSCHL B3,FORD_VIEW F2
      WHERE ((F2.GLAEUBIGERNR=H3.GLAEUBIGERNR AND F2.FORDNR=H3.FORDNR
      AND F2.FORDERGNR=H3.FORDERGNR) OR F2.MAHN_NUM = H3.MAHN_NUM) AND B3.STORNOMM=0
      AND H3.BUCHUNGSGRUPPE = B3.BUCHUNGSGRUPPE AND
      H3.LFDNR = B3.LFDNR AND H3.BUCHUNGSGRUPPE > 5999
      AND H3.BUCHUNGSGRUPPE < 7100 AND (B3.SICHERHEITBEZUG = 1 OR B3.NACHMIETVERTRAGE =1)
      GROUP BY TO_CHAR(ERFASSDATUM,'YYYY/MM')) HA3
      WHERE HD.DATUM=HA2.DATUM (+)
      AND HD.DATUM=HA3.DATUM (+)
      ORDER BY DATUM ASC )
    ORA-00907: missing right parenthesis

    If you format your code it makes it far easier to spot mistakes...
    WITH HIST_VIEW AS (SELECT GLAEUBIGERNR,FORDNR,FORDERGNR,MAHN_NUM,BUCHUNGSGRUPPE,LFDNR,STORNOMM,ERFASSDATUM,BETRAG
                       FROM   TRANS_HIST H
                       WHERE  ERFASSDATUM >=TO_DATE('01.10'||TO_CHAR(ADD_MONTHS(SYSDATE,-9),'YYYY')||' 00.00.00','DD.MM.YYYY HH24:MI:SS')
                       AND   (  H.BUCHUNGSGRUPPE = '8888'
                            OR (H.BUCHUNGSGRUPPE > 5999 AND H.BUCHUNGSGRUPPE < 7100)
         FORD_VIEW AS (SELECT F.GLAEUBIGERNR,F.FORDNR,F.FORDERGNR,A.MAHN_NUM
                       FROM   FRD_ACCT F,ANS_PRCH A
                       WHERE  F.GLAEUBIGERNR=A.GLAEUBIGERNR(+)
                       AND    F.FORDNR=A.FORDNR(+)
                       AND    F.FORDERGNR=A.FORDERGNR(+)
                       AND    NVL(F.INDIVIDUALFLAG,0)=0
                       AND    A.RANGMM=1
    SELECT HD.DATUM DATUM
          ,HA2.GELDEINGAENGE_INSG-NVL(HA3.VERWERTUNGSERLOESE,0) GELDEINGANG
          ,HA3.VERWERTUNGSERLOESE
    FROM  (SELECT DISTINCT(TO_CHAR(ERFASSDATUM,'YYYY/MM')) DATUM
           FROM   HIST_VIEW H1
                 ,BUCHUNGSSCHL B1
           WHERE  B1.STORNOMM=0
           AND    H1.BUCHUNGSGRUPPE = B1.BUCHUNGSGRUPPE
           AND    H1.LFDNR = B1.LFDNR
           AND   (  H1.BUCHUNGSGRUPPE = '8888'
                OR (H1.BUCHUNGSGRUPPE > 5999 AND H1.BUCHUNGSGRUPPE < 7100 AND B1.SICHERHEITBEZUG = 1)
          ) HD,
          (SELECT TO_CHAR(ERFASSDATUM,'YYYY/MM') DATUM
                 ,SUM(BETRAG) GELDEINGAENGE_INSG
           FROM   HIST_VIEW H2
                 ,FORD_VIEW F1
           WHERE (
                   (    F1.GLAEUBIGERNR= H2.GLAEUBIGERNR
                    AND F1.FORDNR=H2.FORDNR
                    AND F1.FORDERGNR=H2.FORDERGNR
                 OR
                    F1.MAHN_NUM = H2.MAHN_NUM
           AND   H2.BUCHUNGSGRUPPE = '8888'
           GROUP BY TO_CHAR(ERFASSDATUM,'YYYY/MM')
          ) HA2,
          (SELECT TO_CHAR(ERFASSDATUM,'YYYY/MM') DATUM
                 ,SUM(BETRAG) VERWERTUNGSERLOESE
           FROM   HIST_VIEW H3
                 ,BUCHUNGSSCHL B3
                 ,FORD_VIEW F2
           WHERE (
                   (    F2.GLAEUBIGERNR=H3.GLAEUBIGERNR
                    AND F2.FORDNR=H3.FORDNR
                    AND F2.FORDERGNR=H3.FORDERGNR
                 OR
                   F2.MAHN_NUM = H3.MAHN_NUM
           AND B3.STORNOMM=0
           AND H3.BUCHUNGSGRUPPE = B3.BUCHUNGSGRUPPE
           AND H3.LFDNR = B3.LFDNR
           AND H3.BUCHUNGSGRUPPE > 5999
           AND H3.BUCHUNGSGRUPPE < 7100
           AND (B3.SICHERHEITBEZUG = 1 OR B3.NACHMIETVERTRAGE =1)
           GROUP BY TO_CHAR(ERFASSDATUM,'YYYY/MM')
          ) HA3
    WHERE HD.DATUM=HA2.DATUM (+)
    AND   HD.DATUM=HA3.DATUM (+)
    ORDER BY DATUM ASC
    ) <--- What's this doing on the end?Remove that last bracket and you should be ok.
    I took the liberty of putting the subquery factoring at the beginning, so see if that works.

  • Use of WITH clause

    Hi,
    I am using Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 .
    I am working in a procedure where I want to manipulate the data produced by a WITH AS clause.  But it is giving "PL/SQL: ORA-00942: table or view does not exist" error. A small example to illustrate my problem is given below. Here in the example am just trying to get a replaced string by using the out put of a WITH AS clause.
    SET SERVEROUTPUT ON;
    DECLARE
    CNT INTEGER;
    LETTER CHAR(1);
    REPLACED_STRING VARCHAR2(10);
    BEGIN
    REPLACED_STRING := 'ABC';
    WITH T AS
      (SELECT 'ABC' VAL FROM DUAL),
      TMP (LEN, SUBVAL) AS
      (SELECT LENGTH(VAL) LEN,
        SUBSTR(VAL, 1, INSTR(VAL, 'B', 1, 1)) SUBVAL
       FROM T
       UNION ALL
       SELECT LENGTH(VAL)-1 LEN,
       SUBSTR(VAL, 2, INSTR(VAL, 'C', 1, 1)) SUBVAL
       FROM T
      SELECT COUNT(*) INTO CNT FROM TMP,T ;
      FOR I IN 1..CNT LOOP
      SELECT SUBSTR(SUBVAL,1,1) INTO LETTER FROM  TMP,T;
      SELECT REPLACE(REPLACED_STRING,LETTER,'X')INTO REPLACED_STRING FROM DUAL;
      DBMS_OUTPUT.PUT_LINE(REPLACED_STRING);
    END LOOP;
    END;
    I thought of declaring a cursor which will hold the data produced by WITH clause but it did not work. Can you please let me know what are the possible options to do this.
    Thanks

    I think, I can not use the WITH inside loop as, I want to manipulate on data resulted by WITH reading row by row from it. I have a complex procedure and I wont be able to explain that scenario here and thus i came up with a similar problem through a very simple example. I will try to explain my problem thru my example here.
    The WITH in my example give an out put as :
    SUBVAL
    AB
    BC
      WITH T AS
      (SELECT 'ABC' VAL FROM DUAL),
      TMP (LEN, SUBVAL) AS
      (SELECT LENGTH(VAL) LEN,
        SUBSTR(VAL, 1, INSTR(VAL, 'B', 1, 1)) SUBVAL
       FROM T
       UNION ALL
       SELECT LENGTH(VAL)-1 LEN,
       SUBSTR(VAL, 2, INSTR(VAL, 'C', 1, 1)) SUBVAL
       FROM T
      SELECT subval FROM TMP,T;
    and then by using this in the PLSQL block mentioned above
      FOR I IN 1..CNT LOOP
      SELECT SUBSTR(SUBVAL,1,1) INTO LETTER FROM  TMP,T;
      SELECT REPLACE(REPLACED_STRING,LETTER,'X')INTO REPLACED_STRING FROM DUAL;
      DBMS_OUTPUT.PUT_LINE(REPLACED_STRING);
      END LOOP;
    I want to have an output like:
    XBC
    XXC
    Please note that nature of my original problem is that I want to manipulate the data given by WITH clause in the same procedure by passing it to other functions/procs to get the desired result. So please advice me following this approach only which would be helpful.
    Thanks

  • Finding a non-recursive algorithm

    I had a project a year ago that was supposed to teach the class recursion. Already being familiar with the Java language, the project was simple.
    The project was, you ahve a "cleaning robot" which cleans an entire room and then returns to the spot it originally was. The room was inputed as a txt file. Everytime you moved to a spot it was automatically cleaned
    The Robot was given to you. The robot class hasthe following methods:
    void move(Direction)   - moves in the direction you gave it.
    boolean canMove(Direction)    -  returns true if the robot can move there without running into a wall
    boolean hasBeen(Direction) - returns true if the robot has cleaned the spot that is in that directionThe Direction class was given to you. It is an enumerated type with the Directions FORWARD, BACWARD, LEFT, RIGHT.
    now the Recursive algorithm is simple:
    private void clean(Direction c, Direction r)
                 move(c); //clean spot in direction
                 for(Direction d : Direction.values()) //go every direction
                      if(canMove(d) && !haveBeen(d)) clean(d,reverse(d));
                 move(r); //go back way we came
    private Direction reverse(Direction d)
                   switch(d)
                      case FORWARD:  d = Direction.BACKWARD; break;
                      case RIGHT:    d = Direction.LEFT;     break;
                      case BACKWARD: d = Direction.FORWARD;  break;
                      case LEFT:     d = Direction.RIGHT;    break;
                 return d;     
    public void start()
             clean(Direction.FORWARD, Direction.BACKWARD);
        }But I am curious how someone would go about implementing a NON recursive algorithm. I understand it would probably be around 2000 lines to implement it. I am not asking anyone to implement it, nor do I plan on it (well..I may one day if I am bored) I am only asking for mere curiosity how someone would go about implementing this non-recursively.
    I have thought about it and thought about it, and the only thing I come up with is recursion. What are your thoughts?

    then I think it'll work.Almost. Your algorithm is flawed in this section:
    move(c);
          // After everything else, come back.
           backtrace.push(reverse(c));What happens when c is the reverse direction? You add to the stack the reverse of the reverse. This means you will continually go back and forth in an infinite loop. I took what you started with and worked it into a working solution:
    private void cleanAll() {
              //imitate the call stack
              Stack<Stack<Direction>> call = new Stack<Stack<Direction>>();
              //holds all the reverse directions     
             Stack<Direction> backtrack = new Stack<Direction>();
             //starting stack
             Stack<Direction> start = new Stack<Direction>();
             //load the starting stack
             for (Direction d : Direction.values())
                  if(canMove(d) && !haveBeen(d))
                       start.push(d);
             call.push(start);
             while (!call.isEmpty()) {
                  Stack<Direction> s = call.pop();
                  while(!s.isEmpty()){
                       Direction c = s.pop();
                      move(c); //clean in this direction
                      backtrack.push(reverse(c)); //record the reverse
                      Stack<Direction> temp = new Stack<Direction>();
                      call.push(s); //stop the current path
                      //load the new stack
                      for (Direction d : Direction.values())
                         if (canMove(d) && !haveBeen(d))
                              temp.push(d);
                     if(!temp.isEmpty())   
                          s = temp; //make temp the current stack
             if(!backtrack.isEmpty())
                  move(backtrack.pop());// After everything else, come back.
        }The problem with your solution is that you use 1 stack for the entire process. In this case, it does not differentiate between moves, so it doesn't KNOW what is a reverse. You need to seperate the reverse directions and treat the different in the special case. In order to do that, you need to know WHEN to reverse. Well you reverse when you have completed a cleaning "path".
    My algorithm implements that "path" as another stack. And adds it to a stack of stacks. What this does is it allows me to know when to reverse. I pop off a stack from the call stack, and then after I am done with that stack I have to reverse, as shown in the code I posted.
    Thank you so much for enhancing my knowledge of Stacks. You have helped emensely. I will be sure to tell my professor that i implemented a iterative solution in about 50 lines of code (extremely lower than the 2000 he hypothosized)

  • WITH clause in CURSOR

    Hi,
    I was going through some docs on using WITH clause in curosr...but coulcn't understand.
    I was going through existing code for customization, that has 'WITH' clause.
    I'm trying to understand below piece of code.
    could you let me know what the below code is about..
      CURSOR CUR_CRK
      IS
      WITH PTLPM_WITH AS
        (SELECT
          /*+ INDEX(P_TR_LOAN_PAST_MONTHLY PK_P_TR_LOAN_PAST_MONTHLY) */
        FROM INF.P_TR_LOAN_PAST_MONTHLY
        WHERE POST_DATE    =P_POST_DATE
        AND TREND_GROUP_ID = 'M'
        AND APPL_ID       IN ('FL','LN')
      UIGL_INF_WITH AS
      (SELECT * FROM INF.U_IM_GALL_LOAN
      XHCC_INF_WITH as
      (SELECT * FROM DWC.XREF_HIER_COST_CENTER_11SEP12 --INF.XREF_HIER_COST_CENTER
      )Thanks.

    Perhaps a simple example will make it clear...
    SQL> ed
    Wrote file afiedt.buf
      1  select e.empno, e.ename, d.dname
      2  from        (select * from emp) e
      3         join (select * from dept) d
      4*        on   (e.deptno = d.deptno)
    SQL> /
         EMPNO ENAME      DNAME
          7369 SMITH      RESEARCH
          7499 ALLEN      SALES
          7521 WARD       SALES
          7566 JONES      RESEARCH
          7654 MARTIN     SALES
          7698 BLAKE      SALES
          7782 CLARK      ACCOUNTING
          7788 SCOTT      RESEARCH
          7839 KING       ACCOUNTING
          7844 TURNER     SALES
          7876 ADAMS      RESEARCH
          7900 JAMES      SALES
          7902 FORD       RESEARCH
          7934 MILLER     ACCOUNTING
    14 rows selected.Ok, a bit of a nonsense query in itself, but it's demonstrating that we have two subqueries that we are getting our data from.
    Now, writing the same query using a WITH clause...
    SQL> ed
    Wrote file afiedt.buf
      1  with e as (select * from emp)
      2      ,d as (select * from dept)
      3  select e.empno, e.ename, d.dname
      4* from   e join d on (e.deptno = d.deptno)
    SQL> /
         EMPNO ENAME      DNAME
          7369 SMITH      RESEARCH
          7499 ALLEN      SALES
          7521 WARD       SALES
          7566 JONES      RESEARCH
          7654 MARTIN     SALES
          7698 BLAKE      SALES
          7782 CLARK      ACCOUNTING
          7788 SCOTT      RESEARCH
          7839 KING       ACCOUNTING
          7844 TURNER     SALES
          7876 ADAMS      RESEARCH
          7900 JAMES      SALES
          7902 FORD       RESEARCH
          7934 MILLER     ACCOUNTING
    14 rows selected.As you can see, the subqueries have been moved out of the main query and put into the WITH clause, and then the main query just references those subqueries aliases.
    In the above example, there's not much point in doing this, but in more complex queries, you may have a subquery that is used several times, in which case having it in the WITH clause means that that subquery is processed just once and used many times, (you can also look at the MATERIALIZE hint to help improve performance with such subqueries if necessary)
    The difficulty with finding this in the documentation is because you will no doubt be trying to search for "WITH", which isn't a very good search term to be using as it's used in the english language too much for an accurate hit... so... when you learn it's called "Subquery Factoring" (because you are factoring out the subqueries from the main query), it then becomes easier to find...
    http://docs.oracle.com/cd/E11882_01/server.112/e26088/statements_10002.htm#i2161315
    ... and you see it's included as part of the documentation for the SQL SELECT statement.

  • N-ary Trees non-recursive traversal algorithms

    Hi,
    Non-recursive traversals are needed when you are unsure how big the tree's will be. So far all the algorithms I have seen either use their own internal stack
    or threading to climb back up the tree.
    Here's my attempt that seems to work but I would value so critical evaluation
    * An extension of the CommonAST that records the line and column
    * number.  The idea was taken from <a target="_top"
    * href="http://www.jguru.com/jguru/faq/view.jsp?EID=62654">Java Guru
    * FAQ: How can I include line numbers in automatically generated
    * ASTs?</a>.
    * @author Oliver Burn
    * @author lkuehne
    * @version 1.0
    * @see <a target="_top" href="http://www.antlr.org/">ANTLR Website</a>
    public class DetailAST
        public AST getFirstChild()
        public AST getNextSibling()
        public int getChildCount()
        public DetailAST getParent()
        public int getChildCount(int aType)
        public String getText()
    }This was cut back just to give you enough info
         public static AST getLeftMostChild(DetailAST ast) {
              DetailAST tempAst = ast.getFirstChild();
              while (tempAst.getFirstChild() != null) {
                   tempAst = tempAst.getFirstChild();
              return tempAst;
         public static void traverseASTInOrder(DetailAST root) {
              DetailAST current = getLeftMostChild(ast);
              processNode(current);
              while (current != root) {
                   if (current == current.getParent().getFirstChild()) {
                        processNode(current.getParent());
                   if (current.getNextSibling() != null) {
                        DetailAST sibling = current.getNextSibling();
                        if (sibling.getChildCount() != 0) {
                             current = (DetailAST) getLeftMostChild(sibling);
                             processNode(current);
                        } else {
                             current = sibling;
                             processNode(current);
                   } else {
                        current = current.getParent();
            // do stuff at inorder traversal
         public static void processNode(AST current) {
              System.out.println(current.getText());
         }for pre-order and post-order John Cowan put forward this algorithm
    http://lists.xml.org/archives/xml-dev/199811/msg00050.html
    traverse(Node node) {
        Node currentNode = node;
        while (currentNode != null) {
          visit(currentNode); //pre order
          // Move down to first child
          Node nextNode = currentNode.getFirstChild();
          if (nextNode != null) {
            currentNode = nextNode;
            continue;
          // No child nodes, so walk tree
          while (currentNode != null) {
            revisit(currentNode)     // post order
            // Move to sibling if possible.
            nextNode = currentNode.getNextSibling();
            if (nextNode != null) {
              currentNode = nextNode;
              break;
           // Move up
           if (currentNode = node)
          currentNode = null;
           else
          currentNode = currentNode.getParentNode();
      }Any comments, criticisms or suggestions ?
    regards
    David Scurrah

    Stack is recursion? As far as I know recursion is when
    function (method) calls itself. Just using some
    Collection, which java.util.Stack implements is not
    recursion.
    Regards
    PawelStacks are used to implement recursive algorithms. What happens in most languages when you make a function call? Each function has an "activation record" where it stores its local variables and parameters. This activation record is usually allocated on a stack. Thus for any recursive algorithm, there is a non-recursive algorithm that uses a stack.
    In the OP's case you don't need a stack because of the peculiarities of tree traversal when you have a pointer to the parent node. (Namely, no cycles and you can get back to where you've been) So the algorithms he gave should work fine.
    My only "criticism" would be that it may be more useful to implement these algorithms with the iterator pattern. So you would have a tree with some functions like:
    public class Tree{
        public TreeIterator inOrderIteraror();
        public TreeIterator preOrderIterator();
    }Where the TreeIterator would look like a java.util.Iterator, except maybe you want some additional utility methods in there or something.
    Other than that, non-recursive algorithms are defnitely the way to go.

  • Non cumulative with non cumulative value change

    hi,
    can any one tell the concept of non cumulative with non cumulative value change with an example with numbers,i am bit confused .
    like we have for non *** inflow and outflow- stocks inflow and outflow so non *** is based on inflow and inflow.
    in the same way any example for above concept

    Hi Venkat,
    If I under stand your question correctly you wish to have an example of where non cumulative values are used and you have given the value of stock? If so here is an example with figures
    So you would do an initial load loading the opening balances of Stock.
    Say material number 12345 = 100 units
    After that, only movements will be posted so Stock will either increase or decrease depending on what image is posted via the change log.
    So there will be a purchase of material 12345 for 50 units so now the balance of material is 150.
    But then you could use or sell 70 units of material 12345 so you stock value would be 80 units
    I hope this makes sense and this is an example that you are after if not please let me know and I'm happy to help
    Regards
    Ben
    PS assign points if useful

  • Using with clause

    I am using the sql with following construct , the explain plan doesn't show that index on col1 of tab1 (used in with clause) as used- it just shows a full table access of a view (system) - result set of query in with clause.
    1. Is it that oracle will not use that index or it doesn't show up
    2. If so then is it good to have that table in join of all the three sqls that i am doing union - atleast in that case the index on col1 gets used (per explain plan).
    with sql1 ( select * from tab1 where col1 = 'y')
    select col_gen
    from tab2 a, sql1 b
    where a.col3 = b.col3
    union
    select col_gen
    from tab3 a, sql1 b
    where a.col3 = b.col4
    Union
    select col_gen
    from tab4 a, sql1 b
    where a.col3 = b.col4

    WITH tab1 AS ( SELECT * FROM tab12 WHERE SESSION_ID = '12')
    SELECT DISTINCT b.unit_key unit_key ,NULL colabc1_KEY ,NULL colabc3_KEY,a.col3_ID
    FROM tab1_col31_MAP a, tab1 b
    WHERE a.unit_id = b.unit_id
    UNION
    SELECT DISTINCT NULL unit_key ,b.colabc1_KEY colabc1_KEY,NULL colabc3_KEY,a.col3_ID
    FROM tab2_col32_MAP a,tab1 b
    WHERE a.colabc1_id = b.colabc1_id
    UNION
    SELECT DISTINCT NULL unit_key,NULL colabc2_KEY,b.colabc3_KEY colabc3_KEY,a.col3_ID
    FROM tab1_col33 a, tab1 b
    WHERE a.colabc3_id = b.colabc3_id
    Operation     Object Name     Rows     Bytes     Cost     Object Node     In/Out     PStart     PStop
    SELECT STATEMENT Optimizer Mode=CHOOSE                                        
    RECURSIVE EXECUTION     SYS_LE_2_0                                   
    TEMP TABLE TRANSFORMATION                                        
    SORT UNIQUE                                        
    UNION-ALL                                        
    NESTED LOOPS                                        
    VIEW                                        
    TABLE ACCESS FULL     SYS_TEMP_0FD9D6603_53EE226                                   
    INDEX RANGE SCAN     SYS_C00133240                                   
    NESTED LOOPS                                        
    VIEW                                        
    TABLE ACCESS FULL     SYS_TEMP_0FD9D6603_53EE226                                   
    INDEX RANGE SCAN     SYS_C00133205                                   
    NESTED LOOPS                                        
    VIEW                                        
    TABLE ACCESS FULL     SYS_TEMP_0FD9D6603_53EE226                                   
    INDEX RANGE SCAN     SYS_C00133202                                   
    ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    SELECT * FROM tab12 WHERE SESSION_ID = '12'
    Operation     Object Name     Rows     Bytes     Cost     Object Node     In/Out     PStart     PStop
    SELECT STATEMENT Optimizer Mode=CHOOSE                                        
    TABLE ACCESS BY INDEX ROWID     tab12                                   
    INDEX RANGE SCAN     IDX     
    Will the temp table transformation use the index used in the query above (ie. IDX)

Maybe you are looking for

  • Why are my holidays duplicated three or four times in iCal?

    On iCal, my US holidays are duplicated three or four times. I do not use MobileMe. I do have it synced with my iPhone but for some reason, only the US holidays are the ones that are duplicated on iCal on my desktop. Anyone know how to correct this?

  • Snow imac

    Roger here need a little help use bought a snow iMac no disks but I have just bought 10.3 to do a clean install which are not here yet, OS9 is on it now but is asking for login and password I am guessing there is no way to by pass this or is there? a

  • Urgent help in modif table inside subroutine

    hi,    i have written as subroutine inside it i am trying to delete from an table  contents of some fields .this table is defined in my main program whic is has an structure defined inside it afetr that i am passing the table to my subroutin n inside

  • Variable section prefix or marker

    Hello, I'm working on a book with numerous chapters and would like to number the chapter pages as follows 1-1, 1-2, 1-3,..... 2-1, 2-2, 2-3,...... etc. where x-y represents (chapter number)-(page number). This format also needs to be in the table of

  • How do i get my videos onto imovie?

    to edit them??? do i need to change the format... how? how can i get videos from my camcorder onto the computer, or photobooth onto imovie?