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

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.

  • ORA-32034: unsupported use of WITH clause-issue

    hello all,
    i am facing some issue when i use with clause and union all operator.
    i have created a dummy code to solve this problem..
    my code is ----------
    with dept_1 as
    (select deptno d1 from detp9 where deptno = 20)
    select empno from emp9 e,dept_d1 where e.empno = dept_1.d1
    UNION ALL
    with dept_1 as
    (select deptno d2 from detp9 where deptno = 30)
    select empno from emp9 e,dept_d2 where e.empno = dept_2.d2.
    when i ran this i gort a message-
    ORA-32034: unsupported use of WITH clause.
    please help me to solve this iisue..
    when i ran it separatly without using union/union all it ran sucessfully..
    thanks in advance..

    923315 wrote:
    hello all,
    i am facing some issue when i use with clause and union all operator.
    i have created a dummy code to solve this problem..
    my code is ----------
    with dept_1 as
    (select deptno d1 from detp9 where deptno = 20)
    select empno from emp9 e,dept_d1 where e.empno = dept_1.d1
    UNION ALL
    with dept_1 as
    (select deptno d2 from detp9 where deptno = 30)
    select empno from emp9 e,dept_d2 where e.empno = dept_2.d2.
    when i ran this i gort a message-
    ORA-32034: unsupported use of WITH clause.
    please help me to solve this iisue..
    when i ran it separatly without using union/union all it ran sucessfully..
    thanks in advance..Well, i don't see anything about these queries that makes sense.
    You are essentially joining emp and dept on EMPNO to DEPTNO ... that doesn't usually make any sense.
    How about you step back from the query which is almost certainly incorrect, and explain your tables, their data and what you need as output?
    Cheers,

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

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

  • 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-32034:unsupported use of WITH clause, anywork arround ? please help

    Hi,
    Can some one please tell me how to write an union statement with two "WITH STATEMENT" . I am trying to create a materialized view ( in testing ) , and I get the error
    CREATE MATERIALIZED VIEW MV_TEST AS
    WITH
    PER AS (SELECT P.PERSONNEL_ID, P.FIRST_NAME EMP_FIRST_NAME, P.SURNAME_ISI EMP_LAST_NAME, P.EXEMPT, P.FTE_ASSIGNED,
            NVL(P.EMPLOYEE_ID,P.VISITOR_NUMBER) EMPLOYEE_VISITOR_ID, ST.CODE_VALUE STAFF_CATEGORY, DIV.DIVISION_NUMBER EMP_DIVISION
            FROM PERSONNEL P , CODES ST , DIVISIONS DIV 
            WHERE P.STAFF_CATEGORY_CODE_ID  = ST.CODE_ID (+) AND P.DIVISION_ID = DIV.DIVISION_ID (+)),
    ACT AS (SELECT AC.ACCOUNT_ID, AC.ACCOUNT_NUMBER, AC.ACCOUNT_NAME, AC.ACCOUNT_START_DATE, AC.ACCOUNT_END_DATE, ACS.ACCOUNT_STATUS_DESIG ACCOUNT_STATUS,
            MGR.FIRST_NAME MGR_FIRST_NAME, MGR.SURNAME_ISI MGR_LAST_NAME,  MGR_DIV.DIVISION_NUMBER MGR_DIVISION
            FROM ACCOUNTS AC, ACCOUNT_STATUS ACS, PERSONNEL MGR, DIVISIONS MGR_DIV
            WHERE AC.ACCOUNT_STATUS_ID = ACS.ACCOUNT_STATUS_ID AND AC.ACCOUNT_MANAGER = MGR.PERSONNEL_ID AND MGR.DIVISION_ID = MGR_DIV.DIVISION_ID (+)),
    LCS AS (SELECT LC.PERSONNEL_ID, LC.ACCOUNT_ID , SUM(NVL(LC.LCS_EFFORT,0)) LCS_EFFORT , AP.PERIOD_YEAR
            FROM
            (SELECT PERSONNEL_ID, ACCOUNT_ID , FISCAL_YEAR_ID , FISCAL_PERIOD_ID , LCS_EFFORT
            FROM LABOR_COMMITED WHERE COMMITED_DATE IS NOT NULL ) LC
            PARTITION BY ( PERSONNEL_ID, ACCOUNT_ID)
            RIGHT OUTER JOIN
            (SELECT FIRST_DAY PERIOD_YEAR, FISCAL_YEAR_ID, FISCAL_SYSTEM_PERIOD_ID FROM ALL_PERIODS WHERE CALENDRICAL_EQUIVALENT IS NOT NULL) AP
            ON (LC.FISCAL_YEAR_ID = AP.FISCAL_YEAR_ID  AND LC.FISCAL_PERIOD_ID = AP.FISCAL_SYSTEM_PERIOD_ID)
            GROUP BY LC.PERSONNEL_ID, LC.ACCOUNT_ID , AP.PERIOD_YEAR)
    SELECT  PER.PERSONNEL_ID , PER.EMP_FIRST_NAME, PER.EMP_LAST_NAME, PER.EXEMPT, PER.FTE_ASSIGNED, PER.EMPLOYEE_VISITOR_ID, PER.STAFF_CATEGORY , PER.EMP_DIVISION,
            ACT.ACCOUNT_NUMBER, ACT.ACCOUNT_NAME, ACT.ACCOUNT_START_DATE, ACT.ACCOUNT_END_DATE, ACT.ACCOUNT_STATUS, ACT.MGR_FIRST_NAME, ACT.MGR_LAST_NAME,
            ACT.MGR_DIVISION, TO_NUMBER(TO_CHAR(LCS.PERIOD_YEAR,'YYYY')) YEARS, LCS.PERIOD_YEAR, LCS.LCS_EFFORT
    FROM    PER, ACT, LCS
    WHERE   PER.PERSONNEL_ID = LCS.PERSONNEL_ID
    AND     ACT.ACCOUNT_ID = LCS.ACCOUNT_ID
    UNION ALL
    WITH
    PER AS (SELECT P.PERSONNEL_ID, P.FIRST_NAME EMP_FIRST_NAME, P.SURNAME_ISI EMP_LAST_NAME, P.EXEMPT, P.FTE_ASSIGNED,
            NVL(P.EMPLOYEE_ID,P.VISITOR_NUMBER) EMPLOYEE_VISITOR_ID, ST.CODE_VALUE STAFF_CATEGORY, DIV.DIVISION_NUMBER EMP_DIVISION
            FROM PERSONNEL P , CODES ST , DIVISIONS DIV 
            WHERE P.STAFF_CATEGORY_CODE_ID  = ST.CODE_ID (+) AND P.DIVISION_ID = DIV.DIVISION_ID (+)),
    ACT AS (SELECT AC.ACCOUNT_ID, AC.ACCOUNT_NUMBER, AC.ACCOUNT_NAME, AC.ACCOUNT_START_DATE, AC.ACCOUNT_END_DATE, ACS.ACCOUNT_STATUS_DESIG ACCOUNT_STATUS,
            MGR.FIRST_NAME MGR_FIRST_NAME, MGR.SURNAME_ISI MGR_LAST_NAME,  MGR_DIV.DIVISION_NUMBER MGR_DIVISION
            FROM ACCOUNTS AC, ACCOUNT_STATUS ACS, PERSONNEL MGR, DIVISIONS MGR_DIV
            WHERE AC.ACCOUNT_STATUS_ID = ACS.ACCOUNT_STATUS_ID AND AC.ACCOUNT_MANAGER = MGR.PERSONNEL_ID AND MGR.DIVISION_ID = MGR_DIV.DIVISION_ID (+)),
    LCE AS (SELECT LE.PERSONNEL_ID, LE.ACCOUNT_ID , SUM(NVL(LE.LCS_EFFORT,0)) LCS_EFFORT , AP.PERIOD_YEAR
            FROM
            (SELECT PERSONNEL_ID, ACCOUNT_ID , FISCAL_YEAR_ID , FISCAL_PERIOD_ID , LCS_EFFORT
            FROM LABOR_EFFORT WHERE LABOR_EFFORT_ID NOT IN (SELECT LABOR_EFFORT_ID FROM LABOR_EFFORT_RETRO_ELEMENTS)) LE
            PARTITION BY ( PERSONNEL_ID, ACCOUNT_ID)
            RIGHT OUTER JOIN
            (SELECT FIRST_DAY PERIOD_YEAR, FISCAL_YEAR_ID, FISCAL_SYSTEM_PERIOD_ID FROM ALL_PERIODS WHERE CALENDRICAL_EQUIVALENT IS NOT NULL) AP
            ON (LE.FISCAL_YEAR_ID = AP.FISCAL_YEAR_ID  AND LE.FISCAL_PERIOD_ID = AP.FISCAL_SYSTEM_PERIOD_ID)
            GROUP BY LE.PERSONNEL_ID, LE.ACCOUNT_ID , AP.PERIOD_YEAR)
    SELECT  PER.EMP_FIRST_NAME, PER.EMP_LAST_NAME, PER.EXEMPT, PER.FTE_ASSIGNED, PER.EMPLOYEE_VISITOR_ID, PER.STAFF_CATEGORY , PER.EMP_DIVISION,
            ACT.ACCOUNT_NUMBER, ACT.ACCOUNT_NAME, ACT.ACCOUNT_START_DATE, ACT.ACCOUNT_END_DATE, ACT.ACCOUNT_STATUS, ACT.MGR_FIRST_NAME, ACT.MGR_LAST_NAME,
            ACT.MGR_DIVISION, TO_NUMBER(TO_CHAR(LCE.PERIOD_YEAR,'YYYY')) YEARS, LCE.PERIOD_YEAR, LCE.LCS_EFFORT
    FROM    PER, ACT, LCE
    WHERE   PER.PERSONNEL_ID = LCE.PERSONNEL_ID
    AND     ACT.ACCOUNT_ID = LCE.ACCOUNT_ID

    Have you tried with SELECT outside the WITH clause ?
    e.g.
    SELECT * FROM (WITH stmt1 goes here..)
    UNION ALL
    SELECT * FROM (WITH stmt2 goes here...).

  • 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

  • Need help with INSERT and WITH clause

    I wrote sql statement which correctly work, but how i use this statment with INSERT query? NEED HELP. when i wrote insert i see error "ORA 32034: unsupported use of with clause"
    with t1 as(
    select a.budat,a.monat as period,b.vtweg,
    c.gjahr,c.buzei,c.shkzg,c.hkont, c.prctr,
    c.wrbtr,
    c.matnr,
    c.menge,
    a.monat,
    c.zuonr
    from ldw_v1.BKPF a,ldw_v1.vbrk b, ldw_v1.bseg c
    where a.AWTYP='VBRK' and a.BLART='RV' and a.BUKRS='8431' and a.awkey=b.vbeln
    and a.bukrs=c.bukrs and a.belnr=c.belnr and a.gjahr=c.gjahr and c.koart='D'
    and c.ktosl is null and c.gsber='4466' and a.gjahr>='2011' and b.vtweg='01'
    ,t2 as(
    select a.BUKRS,a.BELNR, a.GJAHR,t1.vtweg,t1.budat,t1.monat from t1, ldw_v1.bkpf a
    where t1.zuonr=a.xblnr and a.blart='WL' and bukrs='8431'
    ,tcogs as (
    select t2.budat,t2.monat,t2.vtweg, bseg.gjahr,bseg.hkont,bseg.prctr,
    sum(bseg.wrbtr) as COGS,bseg.matnr,bseg.kunnr,sum(bseg.menge) as QUANTITY
    from t2, ldw_v1.bseg
    where t2.bukrs=bseg.bukrs and t2.belnr=bseg.BELNR and t2.gjahr=bseg.gjahr and BSEG.KOART='S'
    group by t2.budat,t2.monat,t2.vtweg, bseg.gjahr,bseg.hkont,bseg.prctr,
    bseg.matnr,bseg.kunnr
    ,t3 as
    select a.budat,a.monat,b.vtweg,
    c.gjahr,c.buzei,c.shkzg,c.hkont, c.prctr,
    case when c.shkzg='S' then c.wrbtr*(-1)
    else c.wrbtr end as NTS,
    c.matnr,c.kunnr,
    c.menge*(-1) as Quantity
    from ldw_v1.BKPF a,ldw_v1.vbrk b, ldw_v1.bseg c
    where a.AWTYP='VBRK' and a.BLART='RV' and a.BUKRS='8431' and a.awkey=b.vbeln
    and a.bukrs=c.bukrs and a.belnr=c.belnr and a.gjahr=c.gjahr and c.koart='S'
    and c.ktosl is null and c.gsber='4466' and a.gjahr>='2011' and b.vtweg='01'
    ,trevenue as (
    select t3.budat,t3.monat,t3.vtweg, t3.gjahr,t3.hkont,t3.prctr,
    sum(t3.NTS) as NTS,t3.matnr,t3.kunnr,sum(t3.QUANTITY) as QUANTITY
    from t3
    group by t3.budat,t3.monat,t3.vtweg, t3.gjahr,t3.hkont,t3.prctr,t3.matnr,t3.kunnr
    select NVL(tr.budat,tc.budat) as budat,
    NVL(tr.monat,tc.monat) as monat,
    NVL(tr.vtweg,tc.vtweg) as vtweg,
    NVL(tr.gjahr, tc.gjahr) as gjahr,
    tr.hkont as NTS_hkont,
    tc.hkont as COGS_hkont,
    NVL(tr.prctr,tc.prctr) as prctr,
    NVL(tr.MATNR, tc.MATNR) as matnr,
    NVL(tr.kunnr, tc.kunnr) as kunnr,
    NVL(tr.Quantity, tc.Quantity) as Quantity,
    tr.NTS as NTS,
    tc.COGS as COGS
    from trevenue TR full outer join tcogs TC
    on TR.BUDAT=TC.BUDAT and TR.MONAT=TC.MONAT and TR.GJAHR=TC.GJAHR
    and TR.MATNR=TC.MATNR and TR.KUNNR=TC.KUNNR and TR.QUANTITY=TC.QUANTITY
    and TR.VTWEG=TC.VTWEG and TR.PRCTR=TC.PRCTR
    Edited by: user13566113 on 25.03.2011 5:26

    Without seeing what you tried it is hard to say what you did wrong, but this is how it would work
    SQL> create table t ( n number );
    Table created.
    SQL> insert into t
      2  with test_data as
      3    (select 1 x from dual union all
      4     select 2 x from dual union all
      5     select 3 x from dual union all
      6     select 4 x from dual)
      7  select x from test_data;
    4 rows created.
    SQL>

  • How to create a view  with "WITH CLAUSE"

    Hi,
    I have a query with "WITH" CLAUSE , I need to create a view on this query. But I am getting error like
    ORA-32034 : Unsupported sue of WITH clause.
    Please help me...!!
    Please find below my query...!!
    WITH RANGE
             AS (SELECT A.MASTERMACHINEID,
                        a.startdate,
                        a.enddate,
                        a.startdate - (1 / 3) + (lvl) * 1 / 3 SHIFT_ST_DT,
                        a.startdate + (lvl) * 1 / 3 AS SHIFT_END_DT,
                        a.quantity,
                        (LEAST ( enddate, TODATE) - GREATEST ( FROMDATE, startdate)) * 24 TOTAL_HRS,
                        (enddate - startdate) * 24 AVAIL,
                       todate,
                       fromdate
                  FROM OMP A,
                       (SELECT LEVEL lvl
                          FROM (SELECT MAX (enddate - startdate) AS diff FROM OMPWORKORDER)
                        CONNECT BY LEVEL <= (diff) * 3),
                       MASTER B
                 WHERE A.MASTERMACHINEID = B.MASTERMACHINEID
                   AND lvl / 3 <=(enddate - startdate) + 1
                ORDER BY SHIFT_ST_DT)
       SELECT shift_date,
              shift_num,
              shift_hrs,
              DECODE (SIGN (SHUT_DWN_TIME), -1, 0, SHUT_DWN_TIME),
              8 - DECODE (SIGN (SHUT_DWN_TIME), -1, 0, SHUT_DWN_TIME) shift_avail_hrs,
              qty,
              total_qty
         FROM (SELECT TRUNC (SHIFT_ST_DT) shift_date,
                      ROW_NUMBER () OVER (PARTITION BY TRUNC (SHIFT_ST_DT) ORDER BY SHIFT_ST_DT) shift_num,
                      8 shift_hrs,
                      (LEAST ( SHIFT_END_DT, TODATE) - GREATEST ( FROMDATE, SHIFT_ST_DT)) * 24
                        SHUT_DWN_TIME,
                      quantity / (avail - TOTAL_HRS) qty,
                      round(((SHIFT_END_DT - SHIFT_ST_DT) * 24 - (LEAST (SHIFT_END_DT, TODATE) - GREATEST (FROMDATE, SHIFT_ST_DT)) * 24)  * QuantiTY / (AVAIL - TOTAL_HRS),2)
                         TOTAL_QTY
                 FROM RANGE A );Regards
    KPR
    Edited by: BluShadow on 17-Mar-2011 09:48
    added {noformat}{noformat} tags for readability                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    Try creating view on following query, if it can help you:
    SELECT shift_date,
        shift_num,
        shift_hrs,
        decode(SIGN(shut_dwn_time),     -1,     0,     shut_dwn_time),
        8 -decode(SIGN(shut_dwn_time),     -1,     0,     shut_dwn_time) shift_avail_hrs,
        qty,
        total_qty
    FROM
            SELECT TRUNC(shift_st_dt) shift_date,
                 row_number() over(PARTITION BY TRUNC(shift_st_dt)
             ORDER BY shift_st_dt) shift_num,
                 8 shift_hrs,
                (least(shift_end_dt,      todate) -greatest(fromdate,      shift_st_dt)) *24 shut_dwn_time,
                 quantity /(avail -total_hrs) qty,
                 ROUND(((shift_end_dt -shift_st_dt) *24 -(least(shift_end_dt,      todate) -greatest(fromdate,      shift_st_dt)) *24) *quantity /(avail -total_hrs),      2) total_qty
             FROM
                  SELECT a.mastermachineid,
                     a.startdate,
                     a.enddate,
                     a.startdate -(1 / 3) +(lvl) *1 / 3 shift_st_dt,
                     a.startdate +(lvl) *1 / 3 AS
                 shift_end_dt,
                     a.quantity,
                    (least(enddate,      todate) -greatest(fromdate,      startdate)) *24 total_hrs,
                    (enddate -startdate) *24 avail,
                     todate,
                     fromdate
                 FROM omp a,
                        (SELECT LEVEL lvl
                     FROM
                        (SELECT MAX(enddate -startdate) AS
                        diff
                         FROM ompworkorder)
                    CONNECT BY LEVEL <=(diff) *3),
                     master b
                 WHERE a.mastermachineid = b.mastermachineid
                 AND lvl / 3 <=(enddate -startdate) + 1
                 ORDER BY shift_st_dt
             ) a
    ;Regards,
    Dipali.l

  • Error in writing nested  WITH CLAUSE

    i am writing SQL Query by making use of with Clause i have use nested with clause .....
    means with clause inside a with clause
    but i am getting error
    ERROR
    Error(73,3): PL/SQL: ORA-32034: unsupported use of WITH clause
    create or replace
    PROCEDURE usp_PatientIPDSummary1
    v_fromdate in date,
    v_todate in date
    AS
    begin
    insert INTO GTT_PATIENTIPDSUMMARY
    ( PATIENTNAME, VISITNO, VISITDATE, DISCHARGEDATE, FIRST_NAME, AGE,
    LAST_NAME, REGISTRATION_NO, HOSPITALISEDDAYS,
    CONTACTCOUNTRY, GENDER, ADMDOCTOR,
    INSERTEDON, INSERTEDMACNAME, INSERTEDBYUSERID
    SELECT fn_PatientFullName(Patient.PatientId) AS patientName,
    Visit.VisitNo, VisitDate,
    Visit.DischargeDate as DischargeDate,
    Visit.DischargeType, Patient.First_Name,
    Patient.Age, Patient.Last_Name, Patient.Registration_No,
    CAST(Visit.DischargeDate - Visit.VisitDate AS NUMERIC) AS HOSPITALISEDDAYS,
    Patient.ContactCountry, Patient.Gender, fn_DoctorFullName(Visit.AdmDocID) AS admDoctor,
    TO_CHAR(Visit.InsertedON,'DD-MON-YYYY') as InsertedON,
    Visit.InsertedMacName,
    Visit.InsertedByUserID
    FROM Visit INNER JOIN
    Patient ON Visit.PatientID = Patient.PatientId
    WHERE (Visit.TypeOfVisit = 'ipd')
    and
    TO_CHAR( Visit.VisitDate,'DD-MON-YYYY')
    between TO_CHAR(v_fromdate,'DD-MON-YYYY')
    and TO_CHAR(v_todate,'DD-MON-YYYY')
    WITH
    Q4
    as
    select count(*) as TotalBedount from bed_mst where deactive =0
    select GTT_PATIENTIPDSUMMARY.InsertedON as "Date"
    Q6.PrevTotal,Q4.TotalBedount as TotalBedCount,
    (Q2.visitCOUNT/Q4.TotalBedount)* 100 as "Occupancy%"
    from
    GTT_PATIENTIPDSUMMARY,Q4,Q6;
    end;

    i have use nested with clause ..... means with clause inside a with clauseNo you haven't - at least not in what you've posted.
    I've tried formatting your unformatted code (You do that next time, thanks)
    WITH Q4 as (select count(*) as TotalBedount
                from   bed_mst
                where  deactive =0
                select GTT_PATIENTIPDSUMMARY.InsertedON as "Date"
                       Q6.PrevTotal,
                       Q4.TotalBedount as TotalBedCount,
                       (Q2.visitCOUNT/Q4.TotalBedount)* 100 as "Occupancy%"
                from
                    GTT_PATIENTIPDSUMMARY, Q4, Q6;From this, it is impossible to tell what you are trying to do, Q2 nd Q6 are defined nowehere,
    and syntax is invalid (As you already know).
    Something else, you should read up on DATE datatype. A DATE is a DATE is a DATE. Dateformats are used
    when converting a DATE into a string and vice versa. Usually this is one done when displaying dates (TO_CHAR)
    or when getting dates from file- or user input (TO_DATE).
    So, this is probably wrong, my guess is that you are (hopefully) inserting into a DATE column:
           TO_CHAR ( visit.insertedon, 'DD-MON-YYYY') AS insertedon,This is definitely wrong, and will give corect result only for some special date intervals:
           AND TO_CHAR ( visit.visitdate, 'DD-MON-YYYY') BETWEEN TO_CHAR ( v_fromdate, 'DD-MON-YYYY')
                                                             AND TO_CHAR ( v_todate, 'DD-MON-YYYY')This is probably wrong, too. DATE - DATE gives NUMBER, and I'm not sure why you would cast
    it into the PL/SQL datatype, NUMERIC.
           CAST (visit.dischargedate - visit.visitdate AS NUMERIC)     Handle:      user21354
    Status Level:      Newbie
    Registered:      Jan 24, 2011
    Total Posts:      179
    Total Questions:      94 *(77 unresolved)*
    You should be more serious about asking questions in a public forum.
    179 posts in three months, and you have still not read the forum FAQ.
    Maybe that is why you get so few questions answered. Or are you just too lazy to follow up on them, marking them as answered?

  • WITH clause unexpectedly causes ORA-00942 in Reports Builder

    I'm posting this in the hope that:
    a) My workaround might help someone if they ever run into the same problem, and/or,
    b) Someone might have a better workaround.
    The problem is that I get unexpected ORA-00942 (table or view does not exist) errors when I try to set the SQL Query Statement property of a Query object in Reports Builder to certain SELECT statements that contain a WITH clause (aka subquery factoring clause).
    For example, the following SELECT statement executes as expected in SQL*Plus...
    SQL> WITH
      2      SUB_QUERY AS
      3      (
      4          SELECT
      5              1 AS X
      6          FROM
      7              DUAL
      8      )
      9  SELECT
    10      INLINE_VIEW.X
    11  FROM   
    12      (
    13          SELECT
    14              NESTED_INLINE_VIEW.X
    15          FROM
    16              (
    17                  SELECT
    18                      SUB_QUERY.X
    19                  FROM
    20                      SUB_QUERY
    21              ) NESTED_INLINE_VIEW
    22      ) INLINE_VIEW;
             X
             1...but when I try to use it as the SQL Query Statement for a Query object in Reports Builder, I get the following error:
    ORA-00942: table or view does not exist
    ==>SUB_QUERY
    My Reports Builder version is 10.1.2.0.2 version and my database version is 10.2.0.3.0.
    The "real" query I have been trying to use is much more complex than this -- this is just the simplest statement I have been able to come up with that causes the problem. In fact, I have some queries that have a similar structure (a WITH clause subquery referenced inside a nested inline view, along with some other things), but strangely do not cause the problem.
    I spent some time researching the problem on Google and Metalink but did not come up with any satisfactory answers. The problem sounds similar to bug 3896963, but bug 3896963 involved UNION ALL, and is supposedly fixed in my version(s).
    I tried various ways of restructuring my "real" query, but with no success -- it's going to be hard to get rid of the WITH clauses. As a "wild guess", I tried various hints (MATERIALIZE, NO_PUSH_PRED, NO_MERGE), again with no success.
    I ended up working around the problem by creating a database package with a function that returns a REF CURSOR based on the query, and then used that in a REF CURSOR query in Reports Builder. It might not be a very elegant workaround, but it works. I just wish I had "given up" and tried it sooner -- I might have saved myself some grief.

    Well, for what it's worth, I didn't end up using a REF CURSOR query after all because...
    If I ran a REP file based on a REF CURSOR query against a different database, or if I ran the REP file after the database package had been dropped and re-created, it failed with the following error:
    REP-8: Run time error in the PL/SQL development environment (DE).
    PDE-PSD001 Could not resolve reference to <Unknown Program Unit> while loading <Unknown> <Unknown>.
    REP-0008: Unexpected memory error while initializing preferences.
    It seems that Reports "binds" the REP file to the timestamp of the database package that defines the REF CURSOR type in order to validate the package at run time. If the timestamp is different, running the REP file will fail with this error. This is apparently bug 1275333 and is described in Metalink Note 272936.1.
    The bug reference and Metalink Note offerred the following workarounds:
    1. Export the database schema that contains the package from one database and import it into the other.
    In some versions, import and export preserve the timestamp, so this would avoid the problem. I didn't try this because it would not be a practical workaround in my situation (upgrade vs. new install).
    2. Recompile the package and manually set the timestamp using the seemingly undocumented ALTER PACKAGE...COMPILE BODY REUSE SETTINGS TIMESTAMP... syntax.
    I didn't try this because I didn't like the idea of having to: a) rely on an undocumented feature, and, b) manually keep track and maintain the timestamps of all the affected packages across several databases (e.g., development, test, and production).
    3. Put the package into a Reports library or into the report itself.
    This didn't work for me because Reports does not understand WITH clauses in PL/SQL. For example, with the example query in my previous post, I get an error like this:
    Error 103 at line {line defining name of factored subquery}, column {first column in line defining name of factored subquery}
    Encountered the symbol "SUB_QUERY" when expecting one of the following:
    &lt;a SQL statement&gt;
    4. Use an RDF file instead of a REP file.
    I didn't use this workaround because I wanted to protect the design of the report by using a REP file instead of an RDF file.
    So instead, I:
    1. Created a database package containing a pipelined function that returned the results of the WITH clause query that Reports did not "understand".
    2. Used an SQL query in my report of the form
    SELECT * FROM TABLE(MY_PACKAGE.MY_PIPELINED_FUNCTION(arg1, arg2, ...))
    I can drop and re-create the package and run the REP file against another database both without leading to the REP-8 error.

  • WITH CLAUSE: ORA-32034

    Hello,
    I have a query that requires WITH clauses since it reiterates a similar select, so I'm down with 2 WITH clause which I cannot unionize. How can I do this?
    Thanks Pierre
    with DURCDR as (select CALLINGPARTYNUMBER,CALLINGPARTYIMSI,CALLINGPARTYIMEI,CALLEDPARTYNUMBER,CALLEDPAR
    TYIMSI,CALLEDPARTYIMEI,
    CHARGINGSTARTTIME,REDIRECTINGPARTYIMEI,REDIRECTINGPARTYIMSI,REDIRECTINGPARTYNUMB
    ER from bgw_durcdr where CHARGINGSTARTTIME BETWEEN '01-05-2007:00:00:00' and '01-05-2007:23:59:59'
    and (CALLEDPARTYIMEI IN '2980' or CALLINGPARTYIMEI IN '2980' OR REDIRECTINGPARTYIMEI IN '2980'))
    SELECT
    CALLEDPARTYNUMBER,
    CALLEDPARTYIMSI,
    CALLEDPARTYIMEI,
    CHARGINGSTARTTIME
    FROM DURCDR
    UNION
    SELECT
    CALLINGPARTYNUMBER,
    CALLINGPARTYIMSI,
    CALLINGPARTYIMEI,
    CHARGINGSTARTTIME
    FROM DURCDR
    UNION
    SELECT
    REDIRECTINGPARTYIMEI,
    REDIRECTINGPARTYIMSI,
    REDIRECTINGPARTYNUMBER,
    CHARGINGSTARTTIME
    FROM
    DURCDR ==> GET ERROR ORA-32034
    UNION
    WITH EVTCDR AS(select DESTINATION,DESTINATIONIMSI,DESTINATIONIMEI,CHARGINGSTARTTIME,ORIGINIMEI,ORIGINI
    MSI,ORIGIN,REDIRECTINGPA
    RTYIMEI,REDIRECTINGPARTYIMSI,REDIRECTINGPARTYNUMBER FROM BGW_EVTCDR WHERE CHARGINGSTARTTIME BETWEEN '01-05-2007:00:00:00' and '01-05-2007:23:59:59'
    AND( DESTINATIONIMEI IN '2980' OR ORIGINIMEI IN '2980' OR REDIRECTINGPARTYIMEI IN '2980'))
    SELECT
    DESTINATION,
    DESTINATIONIMSI,
    DESTINATIONIMEI,
    CHARGINGSTARTTIME
    FROM EVTCDR
    UNION
    SELECT
    ORIGINIMEI,
    ORIGINIMSI,
    ORIGIN,
    CHARGINGSTARTTIME
    FROM EVTCDR
    UNION
    SELECT
    REDIRECTINGPARTYIMEI,
    REDIRECTINGPARTYIMSI,
    REDIRECTINGPARTYNUMBER,
    CHARGINGSTARTTIME
    FROM EVTCDR;

    (although the example you gave still fails in v10) Really ?
    SQL> select banner from v$version where rownum = 1;
    BANNER
    Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod
    SQL> with d as (select deptno from emp), 
      2  s as (select deptno from dept) 
      3  select * from d 
      4  union 
      5  select * from s;
        DEPTNO
            10
            20
            30
            40Your example works with subquery which is the separate select statement.
    SQL> with t as (select 1 a from dual)
      2  select * from t where a in (
      3  with x as (select 2 b from dual)
      4  select b from x
      5  )
      6  /
    no rows selected
    SQL> with t as (select 1 a from dual),
      2  x as (select 2 b from dual)
      3  select * from t where a in (
      4  select b from x
      5  )
      6  /
    no rows selectedhttp://download-uk.oracle.com/docs/cd/B19306_01/server.102/b14200/statements_10002.htm#i2065646
    Restrictions on Subquery Factoring This clause is subject to the following restrictions:
    You can specify only one subquery_factoring_clause in a single SQL statement. You cannot specify a query_name in its own subquery. However, any query_name defined in the subquery_factoring_clause can be used in any subsequent named query block in the subquery_factoring_clause.
    In a compound query with set operators, you cannot use the query_name for any of the component queries, but you can use the query_name in the FROM clause of any of the component queries.
    Rgds.

  • Help with WITH clause (ORA-24374: define not done before fetch or execute)

    Hi all
    I am uising with clause in SQL and getting this error. Please help ORA-24374: define not done before fetch or execute and fetch
    with dea as
    (SELECT MAX (idnt_value_cd) dea_num_cd,
    MAX (xtl_bpa_idnt_value_eff_dt)dea_eff_dt,
    MAX (idnt_value_cd_term_dt)dea_exp_dt,bpa_id
    FROM xtl_bpa_idnt_value
    WHERE xtl_bpa_idnt_id = 1
    AND merci_util.is_date_range_active
    (xtl_bpa_idnt_value_eff_dt,
    idnt_value_cd_term_dt
    ) = 0
    GROUP BY bpa_id)
    SELECT 'IPLAN' src_sys_name, bp.bp_id src_bp_id, 'INDV' bp_type_cd,
    CAST (NULL AS VARCHAR2 (10)) src_bp_clsfn_cd,
    CAST (NULL AS VARCHAR2 (10)) src_bp_sub_clsfn_cd,
    CAST (NULL AS VARCHAR2 (100)) bp_name, hcp.first_nm first_nm,
    hcp.middle_nm midl_nm, hcp.last_nm last_nm,
    hcp.name_pfx_dcd salu_txt, hcp.name_sufx_dcd sfx_txt,
    birth_yr_cd || birth_mth_cd || birth_day_cd birth_dt,
    gender_dcd gndr_cd, mpro_type.mpro_cd src_pfsnl_dgntn_cd,
    (SELECT spty_nm
    FROM specialty
    WHERE spty_id =
    (SELECT spty_id
    FROM bp_specialty
    WHERE bp_id = bp.bp_id
    AND bp_specialty_id =
    (SELECT MAX (bp_specialty_id)
    FROM bp_specialty
    WHERE bp_id = bp.bp_id)))
    src_prim_mdcl_spty_cd,
    (SELECT spty_nm
    FROM specialty
    WHERE spty_id =
    (SELECT spty_id
    FROM bp_specialty
    WHERE bp_id = bp.bp_id
    AND bp_specialty_id =
    (SELECT MAX (bp_specialty_id) - 1
    FROM bp_specialty
    WHERE bp_id = bp.bp_id)))
    src_sec_mdcl_spty_cd,
    (SELECT spty_nm
    FROM specialty
    WHERE spty_id =
    (SELECT spty_id
    FROM bp_specialty
    WHERE bp_id = bp.bp_id
    AND bp_specialty_id =
    (SELECT MAX (bp_specialty_id) - 2
    FROM bp_specialty
    WHERE bp_id = bp.bp_id)))
    src_tert_mdcl_spty_cd,
    lic.lic_num_cd src_st_lic_num, vhcp.state_cd src_sln_state_cd,
    lic.lic_eff_dt src_st_lic_eff_dt,
    lic.lic_expr_dt src_st_lic_exprn_dt,
    bp_status.bp_status_type_dcd src_bp_actv_ind,
    bp_status.bp_status_eff_dt src_bp_sta_chg_dt,
    mpro_type.mpro_type_dcd titl_txt,
    CAST (NULL AS VARCHAR2 (10)) src_cmeh_bp_id,
    (SELECT xtl_bp_idnt_value_cd
    FROM xtl_bp_idnt_value
    WHERE bp_id = vhcp.hcp_id AND xtl_bp_idnt_id = 6)
    callmax_cust_id,
    CAST (NULL AS VARCHAR2 (10)) wk_num,
    (SELECT xtl_bp_idnt_value_cd
    FROM xtl_bp_idnt_value
    WHERE bp_id = vhcp.hcp_id AND xtl_bp_idnt_id = 26) ims_psbr_num,
    (SELECT xtl_bp_idnt_value_cd
    FROM xtl_bp_idnt_value
    WHERE bp_id = vhcp.hcp_id AND xtl_bp_idnt_id = 22) ama_num,
    (SELECT xtl_bp_idnt_value_cd
    FROM xtl_bp_idnt_value
    WHERE bp_id = vhcp.hcp_id AND xtl_bp_idnt_id = 3) aoa_num,
    (SELECT xtl_bp_idnt_value_cd
    FROM xtl_bp_idnt_value
    WHERE bp_id = vhcp.hcp_id AND xtl_bp_idnt_id = 21) ada_num,
    CAST (NULL AS VARCHAR2 (10)) vet_num,
    (SELECT xtl_bp_idnt_value_cd
    FROM xtl_bp_idnt_value
    WHERE bp_id = vhcp.hcp_id AND xtl_bp_idnt_id = 23) np_num,
    (SELECT xtl_bp_idnt_value_cd
    FROM xtl_bp_idnt_value
    WHERE bp_id = vhcp.hcp_id AND xtl_bp_idnt_id = 20) pa_num,
    CAST (NULL AS VARCHAR2 (10)) pod_num,
    CAST (NULL AS VARCHAR2 (10)) opt_num,
    (SELECT xtl_bp_idnt_value_cd
    FROM xtl_bp_idnt_value
    WHERE bp_id = vhcp.hcp_id AND xtl_bp_idnt_id = 7) tax_id,
    CAST (NULL AS VARCHAR2 (10)) hin_num,
    CAST (NULL AS VARCHAR2 (10)) npi_num,
    vhcp.phone_num_cd bp_off_phn_num, vhcp.fax_num_cd bp_fax_num,
    CAST (NULL AS VARCHAR2 (10)) bp_cell_phn_num,
    CAST (NULL AS VARCHAR2 (10)) bp_pager_num,
    CAST (NULL AS VARCHAR2 (10)) bp_home_phn_num,
    CAST (NULL AS VARCHAR2 (10)) bp_vmail_num,
    vhcp.e_mail_cd bp_email_addr_txt,
    CAST (NULL AS VARCHAR2 (10)) bp_url, vhcp.bpa_id src_bpa_id,
    vhcp.addr_1_ds addr_ln_1_txt, addr_2_ds addr_ln_2_txt,
    CAST (NULL AS VARCHAR2 (10)) addr_ln_3_txt,
    CAST (NULL AS VARCHAR2 (10)) addr_ln_4_txt, city_nm,
    state_nm state_cd, postal_cd zip_5,
    CAST (NULL AS VARCHAR2 (10)) zip_4,
    vhcp.pfrd_ctac_loc_ind pfr_locn_ind,
    DECODE
    (merci_util.is_date_range_active ((SELECT bp_address.eff_dt
    FROM bp_address
    WHERE bpa_id = vhcp.bpa_id),
    (SELECT bp_address.end_dt
    FROM bp_address
    WHERE bpa_id = vhcp.bpa_id)
    0, 'ACTIVE',
    'INACTIVE'
    ) src_bpa_actv_ind,
    TO_CHAR (vhcp.bpa_updt_dtm, ' YYYYMMDD') src_bpa_sta_chg_dt,
    vhcp.prac_loc_ind bpa_off_addr_ind,
    vhcp.ship_to_loc_ind bpa_ship_addr_ind,
    vhcp.pfrd_fncl_loc_ind bpa_bill_addr_ind,
    (SELECT bp_address.mail_loc_ind
    FROM bp_address
    WHERE bpa_id = vhcp.bpa_id) bpa_mail_addr_ind,
    CAST (NULL AS VARCHAR2 (10)) bpa_sm_addr_ind,
    (SELECT bp_address.home_loc_ind
    FROM bp_address
    WHERE bpa_id = vhcp.bpa_id) bpa_home_addr_ind,
    CAST (NULL AS VARCHAR2 (10)) bpa_hdqtr_addr_ind,
    vhcp.affiliation_ind bpa_affl_addr_ind,
    CAST (NULL AS VARCHAR2 (10)) bpa_prov_addr_ind,
    CAST (NULL AS VARCHAR2 (10)) bpa_other_addr_ind,
    dea.dea_num_cd,
    dea.dea_eff_dt,
    dea.dea_exp_dt,
    CAST (NULL AS VARCHAR2 (10)) schd_clas_cd,
    (SELECT MAX (idnt_value_cd) affl_id_cd
    FROM xtl_bpa_idnt_value
    WHERE 1 = 1
    AND xtl_bpa_idnt_id = 3
    AND merci_util.is_date_range_active
    (xtl_bpa_idnt_value_eff_dt,
    idnt_value_cd_term_dt
    ) = 0
    AND xtl_bpa_idnt_value.bpa_id = vhcp.bpa_id
    GROUP BY bpa_id) ims_outlet_num,
    (SELECT MAX (idnt_value_cd) affl_id_cd
    FROM xtl_bpa_idnt_value
    WHERE 1 = 1
    AND xtl_bpa_idnt_id = 6
    AND merci_util.is_date_range_active
    (xtl_bpa_idnt_value_eff_dt,
    idnt_value_cd_term_dt
    ) = 0
    AND xtl_bpa_idnt_value.bpa_id = vhcp.bpa_id
    GROUP BY bpa_id) callmax_afln_id,
    CAST (NULL AS VARCHAR2 (10)) src_cmeh_bpa_id,
    vhcp.bpa_id src_addr_id, vhcp.phone_num_cd bpa_off_num,
    vhcp.fax_num_cd bpa_fax_num,
    CAST (NULL AS VARCHAR2 (10)) bpa_cell_phn_num,
    CAST (NULL AS VARCHAR2 (10)) bpa_pager_num,
    CAST (NULL AS VARCHAR2 (10)) bpa_home_phn_num,
    CAST (NULL AS VARCHAR2 (10)) bpa_vmail_num,
    vhcp.e_mail_cd bpa_email_addr_txt,
    CAST (NULL AS VARCHAR2 (10)) bpa_url,
    CAST (NULL AS VARCHAR2 (10)) bp_filler_1,
    CAST (NULL AS VARCHAR2 (10)) bp_filler_2,
    CAST (NULL AS VARCHAR2 (10)) bp_filler_3,
    CAST (NULL AS VARCHAR2 (10)) bp_filler_4,
    CAST (NULL AS VARCHAR2 (10)) bp_filler_5,
    CAST (NULL AS VARCHAR2 (10)) bpa_filler_1,
    CAST (NULL AS VARCHAR2 (10)) bpa_filler_2,
    CAST (NULL AS VARCHAR2 (10)) bpa_filler_3,
    CAST (NULL AS VARCHAR2 (10)) bpa_filler_4,
    CAST (NULL AS VARCHAR2 (10)) bpa_filler_5,
    max_date (max_date (vhcp.bpa_updt_dtm, vhcp.hcp_updt_dtm),
    bp_status.updt_dtm
    ) updt_dtm,
    SYSDATE refresh_dtm
    FROM business_party bp,
    hcp,
    (SELECT hcp_id, lic_num_cd, MIN (lic_eff_dt) lic_eff_dt,
    MAX (lic_expr_dt) lic_expr_dt
    FROM mpro_govt_org_license
    WHERE 1 = 1
    AND merci_util.is_date_range_active (lic_eff_dt, lic_expr_dt) =
    0
    GROUP BY hcp_id, mpro_type_dcd, geoa_id, lic_num_cd) lic,
    (SELECT code_type_nm, code_value_cd mpro_type_dcd,
    xtl_src_obj_cd mpro_cd
    FROM xtl_src_code_value
    WHERE 1 = 1 AND code_type_nm = 'MPRO_TYPE') mpro_type,
    vm_hcp_address vhcp,
    bp_status,
    dea
    WHERE bp.bp_id = hcp.hcp_id
    AND hcp.hcp_id = lic.hcp_id(+)
    AND dea.bpa_id(+) = vhcp.bpa_id
    AND bp.hcp_ind = 'Y'
    AND hcp.mpro_type_1_dcd = mpro_type.mpro_type_dcd(+)
    AND hcp.hcp_id = vhcp.hcp_id
    AND hcp.srch_ctac_bpa_id = vhcp.bpa_id
    AND hcp.hcp_id = bp_status.bp_id
    and hcp.hcp_id=2200970

    Do you have an Oracle version? Trick question, you do, we just have no idea what it is.
    select * from v$version;Also, do you have a line number where this error occurs? Another trick question, you do, but you haven't posted it :(
    And finally, what are you using to run this query (SQLPLUS, SQLDEVELOPER, TOAD, etc....).
    And finally finally, please use the code tags .... { code } with no spaces so that your code doesn't look like a dictionary vomiting.
    Thanks.

  • Ora-00604 and Ora-00904 in a With Clause

    Hi:
    If I use a “left outer join” in the then following SQL I get a result set, but when I use a “full outer join” I get ora-00604 and ora-00904. Please let me know why this is happening?
    Full Join Example:
    with XYZ as (
    select tp.field1 as APID1
    ,pay.field2 as APAMT1
    from Table1 tp join table2 pay on tp.id = pay.id
    where rownum < 10
    , XYZ2 as (
    select Nvl(pd.field1,0) as PID
    , pd.field2 as PAMT
    from Table1 tp join table3 pd on tp.id = pd.id
    where tp.field1 = -1
    select COALESCE(XYZ.APID1, xyz2.PID,0)as PNM
    , NVL(XYZ.APAMT1, 0) as XYZAMT
    , NVL(xyz2.PAMT, 0) as XYZ2AMT
    from XYZ full outer join XYZ2 on PID = APID1
    Note: the SQL in XYZ2 returns 0 rows.
    The error I get is :
    ORA-00604: error occurred at recursive SQL level 1
    ORA-00904: "from$_subquery$_003"."QCSJ_C003008_12": invalid identifier
    Left Outer Join Example (This returns result):
    with XYZ as (
    select tp.field1 as APID1
    ,pay.field2 as APAMT1
    from Table1 tp join table2 pay on tp.id = pay.id
    where rownum < 10
    , XYZ2 as (
    select Nvl(pd.field1,0) as PID
    , pd.field2 as PAMT
    from Table1 tp join table3 pd on tp.id = pd.id
    where tp.field1 = -1
    select COALESCE(XYZ.APID1, xyz2.PID,0)as PNM
    , NVL(XYZ.APAMT1, 0) as XYZAMT
    , NVL(xyz2.PAMT, 0) as XYZ2AMT
    from XYZ left outer join XYZ2 on PID = APID1
    Note: the SQL in XYZ2 returns 0 rows.
    Thank you,

    Please refer to Doc ID: 311230.1 which has detailed information about these errors.

Maybe you are looking for