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,

Similar Messages

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

  • Updating large table using the WITH CLAUSE or PLSQL

    I tried to perform an update on a table with over 15million records using the merge statement below but it's very slow.
    Can someone help me re-writting this statement using the WITH CLAUSE or a PLSQL statement that will make it run faster?
    my merge statemet:
    MERGE INTO voter dst
    USING (
    SELECT voterid,
    pollingstation || CASE
    WHEN ROW_NUMBER () OVER ( PARTITION BY pollingstation
    ORDER BY surname, firstnames
    ) <= 1000
    THEN 'A'
    WHEN ROW_NUMBER () OVER ( PARTITION BY pollingstation
    ORDER BY surname, firstnames
    ) BETWEEN 1000 AND 2000
    THEN 'B'
    ELSE 'C'
    END AS new_pollingstation
    FROM voter
    ) src
    ON (src.voterid = dst.voterid)
    WHEN MATCHED THEN UPDATE
    SET dst.new_pollingstation = src.new_pollingstation
    the with clause approach:http://www.dba-oracle.com/t_with_clause.htm
    thanks.

    Well, here's your query formatted for people to read...
    MERGE INTO voter dst
    USING (SELECT voterid,
                  pollingstation || CASE WHEN ROW_NUMBER () OVER ( PARTITION BY pollingstation ORDER BY surname, firstnames) <= 1000
                                           THEN 'A'
                                         WHEN ROW_NUMBER () OVER ( PARTITION BY pollingstation ORDER BY surname, firstnames) BETWEEN 1000 AND 2000
                                           THEN 'B'
                                         ELSE 'C'
                                    END AS new_pollingstation
           FROM voter) src
    ON (src.voterid = dst.voterid)
    WHEN MATCHED THEN
    UPDATE SET dst.new_pollingstation = src.new_pollingstation
    ;In future, please read {message:id=9360002} and post relevant details.
    What do you mean when you say it's "slow"? How have you measured this? Have you examined the explain plan?
    Take a read of the threads linked to by the FAQ post: {message:id=9360003} for details of what you need to provide to get help with performance issues.

  • OPEN CURSOR using a WITH clause in the select query

    Hi,
    I am using Oracle 9i. I have a requirement where I have a REFCURSOR as an OUT parameter for my procedure. I have declared the TYPE and created the procedure.
    In the procedure, I am using OPEN <cursor_name> FOR <query>;
    Ideally this works in most of the cases that I have tried earlier. However, in the current case I am using a WITH clause in my query to get the results.
    I need help in understanding if the above mentioned syntax would not allow me to use the WITH clause in the query.

    What error do you get , seems to work ok for me on 10g
    SQL> begin
      2  open :cv for 'with x as (select * from emp)  select * from x';
      3  end;
      4  /
    PL/SQL procedure successfully completed.
    SQL> print :cv
         EMPNO
    ENAME
    JOB              MGR HIREDATE         SAL       COMM     DEPTNO
          7521
    WARD
    SALESMAN        7698 22-FEB-81       1250        500         30
          7566
    JONES
    MANAGER         7839 02-APR-81       2975                    20
         EMPNO

  • 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

  • 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

  • ORA-03115 Error using CLOB with JDBC

    When I try to access CLOB field data with JDBC driver, I gets following error:
    ORA-03115: unsupported network datatype or representation.
    I am using JDBC 8.1.6(Thin), Oracle 8.0.5
    on Linux OS.
    what's the problem ?
    Thank you for any help.
    Taesoo.
    null

    if it is a bug, then its better to upgrade the database to 10.2.0.4. it is the stable verion in 10g.

  • Unable to use the with clause in oracle 9.0.2

    Hi,
    I need to use oracle SQL with clause in oracle 9.0.2 database. Its a 9i feature but i am unable to use it.
    It is giving internal error, when i try to execute it.
    Even for simple query:
    WITH acct_summary as ( select TOT_COLL_AMT from tdc_acct)
    select TOT_COLL_AMT from acct_summary WHERE TOT_COLL_AMT>100;
    Error message while using 8.0.5 sql plus client:
    SP2-0642: SQL*Plus internal error state 2091, context 0:0:0
    Unsafe to proceed
    Please help to find out why i am not able to use the sql with clause in oracle 9.0.2 database.
    Thanks and regards,
    Raajkathir

    Hi Jens Petersen,
    Yes, You are correct. Thank you very much.
    Regards,
    Raja

  • ORA-00932 while using nvl with trunc function

    What happens when trunc is executed on null?
    I am executing the following query:
    "select nvl(trunc(null),sysdate) from dual"
    and this throws "ORA-00932: inconsistent datatypes: expected NUMBER got DATE, error at Line:1 Column:23".
    Whereas "select nvl(null,sysdate) from dual" returns sysdate correctly.
    Also "select trunc(null) from dual" returns null only. So when the returned null is passed through nvl why am I getting exception?
    This is happening in ver 9.2.0.5.0 and 10.2.0.2.0
    There is another observation, which is an issue that we have found in our code, and while trying to fix that we saw the earlier observation.
    SELECT * FROM orgs, dual where
    trunc(SYSDATE) between trunc(orgs.effective_start_date) and nvl(trunc(orgs.effective_end_date),trunc(sysdate))
    Here effective start date and effective end date for orgs are null for all records.
    When we run this query on ver 9.2.0.5.0, this runs without any exception. But when we run this query on ver 10.2.0.2.0, we get the same exception, "ORA-00932: inconsistent datatypes: expected NUMBER got DATE, error at Line:2 Column:95".
    The join with dual is fake, in actual scenario we have join with other tables, but since we are able to replicate with dual, removed all other details to keep this simple.
    Now if we remove the join with dual, the query works fine in both the env.
    SELECT * FROM orgs where
    trunc(SYSDATE) between trunc(orgs.effective_start_date) and nvl(trunc(orgs.effective_end_date),trunc(sysdate))

    What happens when trunc is executed on null?
    I am executing the following query:
    "select nvl(trunc(null),sysdate) from dual"
    and this throws "ORA-00932: inconsistent datatypes:
    expected NUMBER got DATE, error at Line:1
    Column:23".
    Whereas "select nvl(null,sysdate) from dual" returns
    sysdate correctly.
    Also "select trunc(null) from dual" returns null
    only. So when the returned null is passed through nvl
    why am I getting exception?
    This is happening in ver 9.2.0.5.0 and 10.2.0.2.0The first parameter to NVL is determining the expected datatype of the returned column, with the trunc function defaulting that to NUMBER because it's parameter is NULL. The second parameter to NVL needs to match that datatype which it doesn't because it is a date.
    SQL> select nvl(trunc(sysdate), sysdate) as mydate from dual;
    MYDATE
    26/05/2006 00:00:00
    SQL> select nvl(trunc(null), sysdate) as mydate from dual;
    select nvl(trunc(null), sysdate) as mydate from dual
    ERROR at line 1:
    ORA-00932: inconsistent datatypes: expected NUMBER got DATE
    SQL> select nvl(trunc(123), sysdate) as mydate from dual;
    select nvl(trunc(123), sysdate) as mydate from dual
    ERROR at line 1:
    ORA-00932: inconsistent datatypes: expected NUMBER got DATE
    SQL>

  • ORA-31020 when using XML with external DTD or entities

    I'd like to parse XML documents against a modular DTD that references other DTDs. This works fine with Oracle 9i. But after upgrading to 11g, the parsing of XML-instances fails and DBMS_XMLPARSER.parseClob produces ORA-31020.
    The same error occurs even if I simply try to store XML with a reference to an external DTD as xmltype:
    SQL> select xmltype('<?xml version="1.0" encoding="iso-8859-1"?><!DOCTYPE ewl-artikel SYSTEM "http://www.foo.com/example.dtd"><test>123</test>') from dual;
    ERROR:
    ORA-31020: Der Vorgang ist nicht zulässig, Ursache: For security reasons, ftp
    and http access over XDB repository is not allowed on server side
    ORA-06512: in "SYS.XMLTYPE", Zeile 310
    ORA-06512: in Zeile 1
    How can I use external DTDs on remote servers in order to parse XML in an 11g database??? Any ideas for a workaround? Thanks in advance!

    This is my PL/SQL validation procedure:
    procedure validatexml (v_id in number default 0) is
    PARSER DBMS_XMLPARSER.parser;
    DTD_SOURCE clob;
    DTD_DOCUMENT xmldom.DOMDocumentType;
    XML_INSTANCE xmltype;
    BEGIN
    -- load DTD from XDB repository
    SELECT httpuritype('http://example.foo.de/app1/DTD1.dtd').getclob() into DTD_SOURCE from dual;
    -- load XML instance
    select co_xml into XML_INSTANCE from tb_xmltab where co_id=v_id;
    -- parse XML instance
    PARSER := DBMS_XMLPARSER.newParser;
    xmlparser.setValidationMode( PARSER , false);
    xmlparser.parseDTDClob( PARSER , DTD_SOURCE , 'myfirstnode' );
    DTD_DOCUMENT := xmlparser.getDoctype( PARSER );
    xmlparser.setValidationMode( PARSER , true );
    xmlparser.setDoctype( PARSER , DTD_DOCUMENT );
    DBMS_XMLPARSER.parseClob( PARSER , v_xml );
    DBMS_XMLPARSER.freeParser(PARSER);
    htp.print('<P>XML instance succesfully validated!<P>');
    end validatexml;

  • HT1551 I've set up our Apple TV and we used it with no issues for a time but after the first month we have never been able to use it.  Upon purchasing a movie it says that it is downloading the movie then shuts down.

    I have had our media company to see what the problem is a few times but with no success. Anyone able to assist or direct me so that I can once again use my Apple TV?

    I would grab a micro usb cable and restore in iTunes. Or you can take it in to a local Apple store/reseller.
    http://support.apple.com/kb/HT4367

  • Using WMS with Projects_Consolidation Issue

    Hi,
    The Items are received for Projects PO in logical Project Locator. Let us assume two cases
    (a) Same item is being procured under a Project. If Task is same then these PO receipts are put in single project locator. If Task is different, the PO receipts are made in different project locator(s).
    (b) Same item is being procured in different Projects. The items are received in different Project locators.
    ------- No we intend to implement WMS functionality (using Mobile device) in inventory Orgs, so that we can consolidate same items in a single PHYSICAL LOCATOR. This will help in reducing space in warehouse. Also while counting process, multiple logical locators need not be counted. Under Projects, the locator control is dynamic entry, hence put away rule won't work in this case.
    ------- After PO receipts, whether somehow cross project transfer (of same item) is achievable without impacting project accounting under any case.
    Input(s) shall be highly appreciated.
    B/R,
    NIrabh Nayan

    FDM does not perform the consolidation function in HFM. It will caculate a Base Entity if you Enable Consolidation, Force Calculate, and Force Translate in the Integration Settings.

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

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

Maybe you are looking for