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
Similar Messages
-
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-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, -
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. -
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 parenthesisIf 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. -
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,
RaajkathirHi Jens Petersen,
Yes, You are correct. Thank you very much.
Regards,
Raja -
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_IDHave you tried with SELECT outside the WITH clause ?
e.g.
SELECT * FROM (WITH stmt1 goes here..)
UNION ALL
SELECT * FROM (WITH stmt2 goes here...). -
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.col4WITH 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) -
With clause join using ISO JOIN Sysntax
Hi,
One of my query looks like:
SELECT t2.col1,
t3.col1,
t3.col2
FROM t2
JOIN t2 ON t2.col1 = t3.col1;
Now I need to use a WITH clause to hold some values which has to be used to filter the results from the original query. Something like:
with t1 AS (Select col1
FROM tab1)
SELECT t2.col1,
t3.col1,
t3.col2
FROM t2
JOIN t3 ON t2.col1 = t3.col1
WHERE t2.col2 = t1.col1;
But the problem is I have to use t1 in the FROM clause before I can use it in the WHERE clause. My question is how do I use t1 in Where clause without joining with t2 & t3?Hi,
Whenever you have a problem, please post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) from all tables involved, so that the people who want to help you can re-create the problem and test their ideas.
Also post the results you want from that data, and an explanation of how you get those results from that data, with specific examples.
Always say which version of Oracle you're using (for example, 11.2.0.2.0).
See the forum FAQ: https://forums.oracle.com/message/9362002
Do you really need to use a WITH clause? It's hard to tell what you want to do just by looking at some code that doesn't do it, but it looks like you're trying to do this:
SELECT t2.col1,
t3.col1,
t3.col2
FROM t2
JOIN t3 ON t2.col1 = t3.col1
WHERE t2.col2 IN (
SELECT col1
FROM tab1
If you really did need a WITH clause, you could reference it like this
with t1 AS
Select col1
FROM tab1
SELECT t2.col1,
t3.col1,
t3.col2
FROM t2
JOIN t3 ON t2.col1 = t3.col1
WHERE t2.col2 IN (
SELECT col1
FROM t1
Joining t1, like Alberto suggested, is another possibility, but be careful: if t1.col1 is not unique, you may get duplicate rows. -
Construct a Sql block using With Clause to improve the performance
I have got four diff parametrized cursor in my Pl/Sql Procedure. As the performance of the Procedure is very pathetic,so i have been asked to tune the Select statements used in those cursors.
So I am trying to use the With Clause in order to club all those four Select Statements.
I would appreciate if anybody can help me to construct the Sql Block using With Clause.
My DB version is..
Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64bit Production
PL/SQL Release 11.1.0.7.0 - Production
Four Diff cursors are defined below.
CURSOR all_iss (
b_batch_end_date IN TIMESTAMP,
IS
SELECT isb.*
FROM IMPLMN_STEP_BREKPN isb
, ISSUE iss
WHERE isb.issue_id = iss.issue_id
AND iss.issue_status_id = 50738
AND ewo_no IN
(SELECT TO_CHAR(wo_no)
FROM MGO_PLANT_AUDIT
WHERE dml_status = 'U' OR dml_status = 'I')
UNION ALL
SELECT isb.*
FROM IMPLMN_STEP_BREKPN isb
, ISSUE iss
WHERE isb.issue_id = iss.issue_id
AND iss.issue_status_id = 50738
AND CAST (isb.last_updt_timstm AS TIMESTAMP) >=
b_batch_end_date;
CURSOR ewo_plant ( p_ewo_no IN IMPLMN_STEP_BREKPN.ewo_no%TYPE)
IS
SELECT DISTINCT wo_no ,
plant_code
FROM MGO_PLANT
WHERE TO_CHAR(wo_no) = p_ewo_no;
CURSOR iss_ewo_plnt (
p_issue_id IN IMPLMN_STEP_BREKPN.issue_id%TYPE ,
p_ewo_no IN IMPLMN_STEP_BREKPN.EWO_NO%TYPE,
p_plnt_code IN IMPLMN_STEP_BREKPN.PLT_FACLTY_ID%TYPE)
IS
SELECT *
FROM IMPLMN_STEP_BREKPN
WHERE issue_id = p_issue_id
AND ewo_no = p_ewo_no
AND
(plt_faclty_id = p_plnt_code
OR
plt_faclty_id IS NULL);
CURSOR iss_ewo_plnt_count (
p_issue_id IN IMPLMN_STEP_BREKPN.issue_id%TYPE ,
p_ewo_no IN IMPLMN_STEP_BREKPN.EWO_NO%TYPE,
p_plnt_code IN IMPLMN_STEP_BREKPN.PLT_FACLTY_ID%TYPE)
IS
SELECT COUNT(*)
FROM IMPLMN_STEP_BREKPN
WHERE issue_id = p_issue_id
AND ewo_no = p_ewo_no
AND
(plt_faclty_id = p_plnt_code
OR
plt_faclty_id IS NULL);Not tested. Some thing like below. i just made the queries as tables and given name as a,b,c and substituted columns for the parameters used in the 2nd cursor and third cursor. Try like this.
CURSOR all_iss (
b_batch_end_date IN TIMESTAMP,
IS
select a.*,b.*,c.* from
( SELECT isb.*
FROM IMPLMN_STEP_BREKPN isb
, ISSUE iss
WHERE isb.issue_id = iss.issue_id
AND iss.issue_status_id = 50738
AND ewo_no IN
(SELECT TO_CHAR(wo_no)
FROM MGO_PLANT_AUDIT
WHERE dml_status = 'U' OR dml_status = 'I')
UNION ALL
SELECT isb.*
FROM IMPLMN_STEP_BREKPN isb
, ISSUE iss
WHERE isb.issue_id = iss.issue_id
AND iss.issue_status_id = 50738
AND CAST (isb.last_updt_timstm AS TIMESTAMP) >=
b_batch_end_date) a,
( SELECT DISTINCT wo_no ,
plant_code
FROM MGO_PLANT
WHERE TO_CHAR(wo_no) = p_ewo_no) b,
( SELECT *
FROM IMPLMN_STEP_BREKPN
WHERE issue_id = p_issue_id
AND ewo_no = p_ewo_no
plt_faclty_id IS NULL) c
where b.wo_no = c.ewo_no and
c.issue_id = a.issue_id ;
vinodh
Edited by: Vinodh2 on Jul 11, 2010 12:03 PM -
Syntax help needed in update using 'WITH' Clause
Update CP_JP_CORP_FSASA_FEEDUPLOAD_r r
set (
gfrn,
tenor_code,
tenor_description,
exposure_category,
frr,
facility_classification,
limit_amount,
limit_usd,
approval_ccy,
approval_date,
expiry_date,
avail_status_code,
avail_status_desc,
revolving_indicator,
committed_flag,
committed_until_date,
committed_amount,
advised_flag,
advised_amount,
facility_long_description,
booking_unit_code,
extending_unit_code,
extending_unit_short_desc,
approving_unit_code,
approving_unit_short_des,
transaction_type,
branch_no
=
With t as
Select fac.gfrn,fac.tenor_code,fac.tenor_description,fac.exposure_category,fac.frr,
fac.facility_classification,fac.limit_amount,fac.limit_usd,fac.approval_ccy,
fac.approval_date,fac.expiry_date,fac.avail_status_code,fac.avail_status_desc,
fac.revolving_indicator,fac.committed_flag,fac.committed_until_date,fac.committed_amount,
fac.advised_flag,fac.advised_amount,fac.facility_long_description,fac.booking_unit_code,
fac.extending_unit_code,fac.extending_unit_short_desc,fac.approving_unit_code,fac.approving_unit_short_des,
/*'Check' normalflag,
cust.adjusted_orr fsasaorr1stborrower,
'Normal' category1stborrower,
cust.adjusted_orr fsasaorr2ndborrower,
'Normal' category2ndborrower,
cust.adjusted_orr fsasaorrfinal,
'Normal' categoryfinal */
txn.transaction_type,txn.branch_no,txn.gfcid,txn.transaction_id
from cp_fsa_boj_corp_cr_fac_hist fac,
--cp_fsa_boj_corp_cr_cust_hist cust,
cp_fsa_boj_corp_cr_txn_hist txn
where fac.gfcid = txn.gfcid
and fac.facility_id = txn.facility_id
and fac.as_of_date = txn.as_of_date
and to_char(fac.as_of_date,'yyyymm') = p_financial_period
and fac.as_of_date = last_day(fac.as_of_date)
select t.gfrn,
t.tenor_code,
t.tenor_description,
t.exposure_category,
t.frr,
t.facility_classification,
t.limit_amount,
t.limit_usd,
t.approval_ccy,
t.approval_date,
t.expiry_date,
t.avail_status_code,
t.avail_status_desc,
t.revolving_indicator,
t.committed_flag,
t.committed_until_date,
t.committed_amount,
t.advised_flag,
t.advised_amount,
t.facility_long_description
t.booking_unit_code,
t.extending_unit_code,
t.extending_unit_short_desc,
t.approving_unit_code,
t.approving_unit_short_des,
t.transaction_type,
t.branch_no
from t
where r.financialperiod = p_financial_period
and exists
Select 1
from t
where t.transaction_id = r.ce_trans_id
)I'm facing syntax problemHii All,
This is my actual update.(I stopped performing dml operations in cursors following Karthick Arp) :-)
Update CP_JP_CORP_FSASA_FEEDUPLOAD_r r
set (
gfrn,
tenor_code,
tenor_description,
exposure_category,
frr,
facility_classification,
limit_amount,
limit_usd,
approval_ccy,
approval_date,
expiry_date,
avail_status_code,
avail_status_desc,
revolving_indicator,
committed_flag,
committed_until_date,
committed_amount,
advised_flag,
advised_amount,
facility_long_description,
booking_unit_code,
extending_unit_code,
extending_unit_short_desc,
approving_unit_code,
approving_unit_short_des,
transaction_type,
branch_no
= (
Select fac.gfrn,fac.tenor_code,fac.tenor_description,fac.exposure_category,fac.frr,
fac.facility_classification,fac.limit_amount,fac.limit_usd,fac.approval_ccy,
fac.approval_date,fac.expiry_date,fac.avail_status_code,fac.avail_status_desc,
fac.revolving_indicator,fac.committed_flag,fac.committed_until_date,fac.committed_amount,
fac.advised_flag,fac.advised_amount,fac.facility_long_description,fac.booking_unit_code,
fac.extending_unit_code,fac.extending_unit_short_desc,fac.approving_unit_code,fac.approving_unit_short_des,
txn.transaction_type,txn.branch_no
from cp_fsa_boj_corp_cr_fac_hist fac,
--cp_fsa_boj_corp_cr_cust_hist cust,
cp_fsa_boj_corp_cr_txn_hist txn
where fac.gfcid = txn.gfcid
and fac.facility_id = txn.facility_id
and fac.as_of_date = txn.as_of_date
and to_char(fac.as_of_date,'yyyymm') = p_financial_period
and fac.as_of_date = last_day(fac.as_of_date)
where Exists
Select 1
from cp_fsa_boj_corp_cr_fac_hist fac,
cp_fsa_boj_corp_cr_txn_hist txn
where fac.gfcid = txn.gfcid
and fac.facility_id = txn.facility_id
and fac.as_of_date = txn.as_of_date
and to_char(fac.as_of_date,'yyyymm') = p_financial_period
and fac.as_of_date = last_day(fac.as_of_date)
and txn.transaction_id = r.ce_trans_id
)Now in my update I'm using same 'SELECT' twice once in 'SET' and again in 'EXISTS' clause. I'd like to make use of 'WITH' Clause and avoid unnecessary 'SELECT' . Please help me. -
Can a SQL WITH Clause be used in Materialized View
Hello,
Can we use SQL WITH clause in Materialized View.
ThanksHello,
Here is an example
CREATE MATERIALIZED VIEW MV_TEST
BUILD IMMEDIATE
REFRESH FORCE ON DEMAND
AS
WITH t AS (SELECT owner, object_type, COUNT ( * )
FROM my_objects
GROUP BY object_type, owner)
SELECT *
FROM t
WHERE owner IN ('SYS', 'SYSTEM');Regards -
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:26Without 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> -
Need help in 'WITH CLAUSE' Query
Hello Gurus,
I am trying to calculate the count of distinct members for each provid.
I am using the with clause to get information regarding the provid.
WITH T AS
(SELECT a.UD_ID MRR_ID,
A.UD_LASTNAME LAST_NAME,
A.UD_FIRSTNAME FIRST_NAME,
COUNT(DISTINCT DP.PA_PROVIDERID) PROVIDERS_ASSIGNED
FROM (SELECT UD.UD_ID,
UD_LASTNAME,
UD_FIRSTNAME
FROM USER_DETAILS UD,
MAP_USERS_TO_ROLES MR
WHERE MR.MUR_UR_ID_REF = 1000
AND MR.MUR_UD_ID_REF = UD.UD_ID) A,
D4C_PROVIDER_ASSIGNMENT DP
WHERE A.UD_ID = DP.PA_ASSIGNEDTO
AND dp.pa_status ='A'
GROUP BY A.UD_ID,
A.UD_LASTNAME,
A.UD_FIRSTNAME
ORDER BY 3 DESC) OUTPUT of just above query without WITH clause.
MRR_ID LAST_NAME FIRST_NAME PROVIDERS_ASSIGNED
1229 mrrTest mrrTest 4
1228 mrr2Last mrr2First 5
1230 mrr1Last mrr1First 7
1226 Panwar SIngh 1
1181 MRRLast MRRTest 4
1221 One MRR 1
1322 Thakuria Bibhuthi 2I am creating this and get all the information to show on front end. Now I want to calculate the no of members as per the providers assigned for each MRR_ID
Below query show the no of members for all the providers assigned to a provider.
ex:
SELECT * FROM (
SELECT COUNT(DISTINCT dmpc_hicn) countmember
FROM D4C_HICN_PROVIDER_claims a WHERE trim(DPMC_PROVIDER_NO) IN
(SELECT trim(pa_providerid)
FROM d4c_provider_assignment
WHERE pa_assignedto = 1181 (mrr_id) --here i have use the mrrid from with clause and get the member count with all the columns coming from WITH CLAUSE.
AND pa_roleid = 1000
AND PA_STATUS ='A'
GROUP BY a.dmpc_ss_id_ref)Right now I am using materialized view i dont wanna use the same..
I am sending the materialized view code as well what i am doing ..
( SELECT SUM(member_count)member_count_bynpi ,mrr_id FROM (
(SELECT count(DISTINCT hp.dmpc_hicn) member_count,hp.DMPC_SS_ID_REF ,a1.ud_id mrr_id FROM D4C_HICN_PROVIDER_claims hp ,
(SELECT a.UD_ID ,DP.PA_PROVIDERID
FROM (SELECT UD.UD_ID, UD_LASTNAME, UD_FIRSTNAME
FROM USER_DETAILS UD, MAP_USERS_TO_ROLES MR
WHERE MR.MUR_UR_ID_REF = 1000
AND MR.MUR_UD_ID_REF = UD.UD_ID) A,
D4C_PROVIDER_ASSIGNMENT DP
WHERE A.UD_ID = DP.PA_ASSIGNEDTO
AND dp.pa_status ='A'
/*AND dp.PA_ASSIGNEDTO = 1221*/) a1
WHERE trim(a1.PA_PROVIDERID) = trim(hp.dpmc_provider_no)
GROUP BY a1.ud_id,hp.DMPC_SS_ID_REF))
GROUP BY mrr_id)Please help me to write the code with the materialized view. Thanks in Advance.
Kind regards,
UP
Edited by: BluShadow on 22-Aug-2011 07:58
fixed {noformat}{noformat} tags. Please use lowercase "code" rather than uppercase "CODE" in the tags.Probably, this may help
WITH T1 as(
SELECT UD.UD_ID,
UD_LASTNAME,
UD_FIRSTNAME
FROM USER_DETAILS UD, MAP_USERS_TO_ROLES MR
WHERE MR.MUR_UR_ID_REF = 1000
AND MR.MUR_UD_ID_REF = UD.UD_ID)
T2 as (SELECT a.UD_ID ,DP.PA_PROVIDERID
FROM T1 A, D4C_PROVIDER_ASSIGNMENT DP
WHERE A.UD_ID = DP.PA_ASSIGNEDTO
AND dp.pa_status ='A')
T3 as(SELECT count(DISTINCT hp.dmpc_hicn) member_count,
hp.DMPC_SS_ID_REF ,
a1.ud_id mrr_id
FROM T2 A1 ,D4C_HICN_PROVIDER_claims hp
WHERE trim(a1.PA_PROVIDERID) = trim(hp.dpmc_provider_no)
GROUP BY a1.ud_id,hp.DMPC_SS_ID_REF)
SELECT SUM(member_count)member_count_bynpi ,mrr_id from T3
GROUP BY mrr_id -
In a previous post I asked a question in regards to showing all the days between now and sysdate +14. I got an answer back an was able to manipulate the code in sql and get it to run returning the necessary results. Now when I try to copy and paste the code into and LOV the LOV saves fine but when I run the form I get an ERR-1000 Unable to Determine LOV along with ORA-06559 an INTO clause is expected with this select statemt. Can you not put With clause in an LOV lookup?
My SQL statement is below. Thanks! Amber
with t as (
select
trunc(sysdate) + 1 + (rownum - 1) / 2 d
from
dual
connect
by rownum <= 28)
, call_info as (
select
c.schedule_id, c.call_date, c.call_identifier
from uid_csr_schedule c
union select
c2.schedule_id, c2.call_date, c2.call_identifier
from uid_csr_schedule c2
select
to_char(d, 'fmDy DD/MM/YYYY AM') l
, d v
from
t
where
100 > (select
count(call_identifier)
from
call_info ci
where
ci.call_date = t.d);mtuser,
Since the LOV queries are executed dynamically, I guess I'm not totally surprised there was a problem?
Since that's the case, I would think your LOV query might run more efficiently by defining the entire query as a view, not use the WITH clause. I didn't see anything in your LOV query that would make this require dynamic input from the Apex form, though maybe you simplified it.
Good luck,
Stew
Maybe you are looking for
-
Change the Text in Linked TFL on the fly
I have 3 TFL fields on the stage. They are linked so the text overflow from the first spills into the subsequent fields 2 and 3. I want to change the text dynamically but when I do the overflow text do not "overflow" into the other fields. It is
-
Reporting on emails in a shared mailbox
hi We have a customer service team that has to monitor and respond to several different email addresses (e.g. servcie@companya, service@companyb, info@companya etc). We are looking at using one or more shared mailboxes for this but need to be able t
-
Generate signal f=50 Hz with NI-9264
Hi. i'm Sorin. I need to generate a sine waveform with f=50 Hz, U=3Vrms. I have a C module, NI-9264. Is it any good ? Or it can only generates Vcc ? I only have C modules: AI for RTD, V,mA, universal, and AO for V and mA. What can i use? Thanks. S
-
Random record retrieval problem
At this point I'm sort of desperate as this has been going on for a few weeks now. I missed this part of the forum an dposted the problem here: thread If anyone can help I would very much apprecfiate that!
-
I have trouble to log in facetime with my Mac air. Is anyone can help?
I have trouble to log in face time with my Macbook Air. Is anyone can help?