With Clause in LOV
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
Similar Messages
-
Bug in WITH clause (subquery factoring clause) in Oracle 11?
I'm using WITH to perform a set comparison in order to qualify a given query as correct or incorrect regarding an existing solution. However, the query does not give the expected result - an empty set - when comparing the solution to itself in Oracle 11 whereas it does in Oracle 10. A minimal example os posted below as script. There are also some observations about changes to the tables or the query that make Oracle 11 returning correct results but in my opinion these changes must not change the semantics of the queries.
Is this a bug or am I getting something wrong? The Oracle versions are mentioned in the script.
-- Bug in WITH clause (subquery factoring clause)
-- in Oracle Database 11g Enterprise Edition 11.2.0.1.0?
DROP TABLE B PURGE;
DROP TABLE K PURGE;
DROP TABLE S PURGE;
CREATE TABLE S (
m number NOT NULL,
x varchar2(30) NOT NULL
CREATE TABLE K (
k char(2) NOT NULL,
x varchar2(50) NOT NULL
CREATE TABLE B (
m number NOT NULL ,
k char(2) NOT NULL ,
n number
INSERT INTO S VALUES(1, 'h');
INSERT INTO S VALUES(2, 'l');
INSERT INTO S VALUES(3, 'm');
INSERT INTO K VALUES('k1', 'd');
INSERT INTO K VALUES('k2', 'i');
INSERT INTO K VALUES('k3', 'm');
INSERT INTO K VALUES('k4', 't');
INSERT INTO K VALUES('k5', 't');
INSERT INTO K VALUES('k6', 's');
INSERT INTO B VALUES(1, 'k1', 40);
INSERT INTO B VALUES(1, 'k2', 30);
INSERT INTO B VALUES(1, 'k4', 50);
INSERT INTO B VALUES(3, 'k1', 10);
INSERT INTO B VALUES(3, 'k2', 20);
INSERT INTO B VALUES(3, 'k1', 30);
INSERT INTO B VALUES(3, 'k6', 90);
COMMIT;
ALTER TABLE S ADD CONSTRAINT S_pk PRIMARY KEY (m);
ALTER TABLE K ADD CONSTRAINT K_pk PRIMARY KEY (k);
ALTER TABLE B ADD CONSTRAINT B_S_fk
FOREIGN KEY (m) REFERENCES S(m) ON DELETE CASCADE;
CREATE OR REPLACE VIEW v AS
SELECT S.m, B.n
FROM S JOIN B ON S.m=B.m JOIN K ON B.k=K.k
WHERE K.x='d'
ORDER BY B.n DESC;
-- Query 1: Result should be 0
WITH q AS
SELECT S.m, B.n
FROM S JOIN B ON S.m=B.m JOIN K ON B.k=K.k
WHERE K.x='d'
ORDER BY B.n DESC
SELECT COUNT(*)
FROM
SELECT * FROM q
MINUS
SELECT * FROM v
UNION ALL
SELECT * FROM v
MINUS
SELECT * FROM q
-- COUNT(*)
-- 6
-- 1 rows selected
-- Query 2: Result set should be empty (Query 1 without counting)
WITH q AS
SELECT S.m, B.n
FROM S JOIN B ON S.m=B.m JOIN K ON B.k=K.k
WHERE K.x='d'
ORDER BY B.n DESC
SELECT *
FROM
SELECT * FROM q
MINUS
SELECT * FROM v
UNION ALL
SELECT * FROM v
MINUS
SELECT * FROM q
-- M N
-- null 10
-- null 30
-- null 40
-- 1 40
-- 3 10
-- 3 30
-- 6 rows selected
-- Observations:
-- Incorrect results in Oracle Database 11g Enterprise Edition 11.2.0.1.0:
-- Query 1 returns 6, Query 2 returns six rows.
-- Correct in Oracle Database 10g Enterprise Edition 10.2.0.1.0.
-- Correct without the foreign key.
-- Correct if attribute x is renamed in S or K.
-- Correct if attribute x is left out in S.
-- Correct without the ORDER BY clause in the definition of q.
-- Only two results if the primary key on K is left out.
-- Correct without any change if not using WITH but subqueries (see below).
-- Fixed queries
-- Query 1b: Result should be 0
SELECT COUNT(*)
FROM
SELECT * FROM
SELECT S.m, B.n
FROM S JOIN B ON S.m=B.m JOIN K ON B.k=K.k
WHERE K.x='d'
ORDER BY B.n DESC
MINUS
SELECT * FROM v
UNION ALL
SELECT * FROM v
MINUS
SELECT * FROM
SELECT S.m, B.n
FROM S JOIN B ON S.m=B.m JOIN K ON B.k=K.k
WHERE K.x='d'
ORDER BY B.n DESC
-- COUNT(*)
-- 0
-- 1 rows selected
-- Query 2b: Result set shoud be empty (Query 1b without counting)
SELECT *
FROM
SELECT * FROM
SELECT S.m, B.n
FROM S JOIN B ON S.m=B.m JOIN K ON B.k=K.k
WHERE K.x='d'
ORDER BY B.n DESC
MINUS
SELECT * FROM v
UNION ALL
SELECT * FROM v
MINUS
SELECT * FROM
SELECT S.m, B.n
FROM S JOIN B ON S.m=B.m JOIN K ON B.k=K.k
WHERE K.x='d'
ORDER BY B.n DESC
-- M N
-- 0 rows selectedYou're all gonna love this one.....
The WITH clause works. But not easily.
Go ahead, build the query, (as noted in a recent thread, I, too, always use views), set the grants and make sure DISCOVERER and EULOWNER have SELECT privs.
1. Log into Disco Admin as EULOWNER. Trust me.
2. Add the view as a folder to the business area.
3. Log into Disco Desktop as EULOWNER. Don't laugh. It gets better.
4. Build the workbook and the worksheet (or just the worksheet if apropos)
5. Set the appropriate "sharing" roles and such
6. Save the workbook to the database.
7. Save the workbook to your computer.
8. Log out of Desktop.
9. Log back into Desktop as whatever, whoever you usually are to work.
10. elect "open existing workbook"
11. Select icon for "open from my computer". See? I told you it would get better!
12. Open the save .dis file from your computer.
13. Save it to the database.
14. Open a web browser and from there, you're on your own.
Fortran in VMS. Much easier and faster. I'm convinced the proliferation of the web is a detriment to the world at large...On the other hand, I'm also waiting for the Dodgers to return to Brooklyn. -
With clause - subquery factoring
I've got a script that looks like this:
with X as (select * from atable)
select x1.*, x2.*
from X x1,
X x2
This works perfectly well in SQL*Plus, in PL/SQL, etc. Yet when I try to add it as "New Folder from Database" to an existing Business area in Discoverer, I get the infamous "ORA-03001 Unimplemented Feature".
What am I doing wrong?
Oracle 9i, Disco 9.0.4You're all gonna love this one.....
The WITH clause works. But not easily.
Go ahead, build the query, (as noted in a recent thread, I, too, always use views), set the grants and make sure DISCOVERER and EULOWNER have SELECT privs.
1. Log into Disco Admin as EULOWNER. Trust me.
2. Add the view as a folder to the business area.
3. Log into Disco Desktop as EULOWNER. Don't laugh. It gets better.
4. Build the workbook and the worksheet (or just the worksheet if apropos)
5. Set the appropriate "sharing" roles and such
6. Save the workbook to the database.
7. Save the workbook to your computer.
8. Log out of Desktop.
9. Log back into Desktop as whatever, whoever you usually are to work.
10. elect "open existing workbook"
11. Select icon for "open from my computer". See? I told you it would get better!
12. Open the save .dis file from your computer.
13. Save it to the database.
14. Open a web browser and from there, you're on your own.
Fortran in VMS. Much easier and faster. I'm convinced the proliferation of the web is a detriment to the world at large...On the other hand, I'm also waiting for the Dodgers to return to Brooklyn. -
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. -
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 -
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> -
Report with multiplying columns and WITH clause
Hello
I saw sth strange in my report. I assume that it could happens very often.
I have report with few columns which two of them ar most complicated (many joins subqueries aggreagations on joined values etc.) These two columns (i.e C3,C4) should be multiplied (C3*C4).
When i do pure report without multiplying only columns C1,C2,C3,C4 everything is ok - duration about 15 sec. but... when I put next column on report which multiply these columns (in Answers C5=C3*C4)
I wait 3-4 minutes and my database hungs :(. After investigation I saw that in first case to databese goes pure "SELECT" statement it means:
"Select ... as C1, ... as C2, max(...) as C3, sum(xxx)... C4 from yyy,sss,ttt WHERE aaa"
but in second case BI uses WITH clause it means:
WITH SAWITH0 AS
( Select ... as C1, ... as C2, max(...) as C3, sum(xxx)... C4 from yyy,sss,ttt WHERE aaa )
SELECT SAWITH0.C1 as C1,
SAWITH0.C2 as C2,
SAWITH0.C3 as C3,
SAWITH0.C4 as C4,
SAWITH0.C3*SAWITH0.C4 as C5 FROM SSS
and this statement is long runninq query and kills my database :(.
I checked that SQL like this:
Select ... as C1, ... as C2, max(...) as C3, sum(xxx)... C4, max(...)*sum(xxx)... As C5 from yyy,sss,ttt WHERE aaa" -
runs few times faster than that above
I know that I can do this multiply in business model layer but sometimes users can multiply(or other operations) on columns in reports without my knowledge and it kills my db :(. Where is bug? Why SQLs with WITH clause takes so much db time?
Thank you for each kind of helpWITH clause or Subquery Factoring allows the set of data to be reused multiple times within the SQL. Oracle will usually materialize the data into a temporary table (you will see it if you take an explain plan of the SQL).
I would be surprised if it was the actual WITH clause that was causing the performance issue, however you can test this by turning the WITH clause feature off. Go to the Physical model, right mouse click on your Database > Properties > Features Tab, scroll down to WITH_CLAUSE_SUPPORTED and switch it off.
I'd be interested to know if you do see actual improvement.
Good Luck. -
i am writing these SQL Lines in my stored procedure i am using with clause i am getting error when i perform
inner join
With WardItemsDtl as ( SELECT WardItemDtl_ID,
WardTransID,
wdDtl.ItemID,
SUM(ItemQty) ItemQty,
ReceivedWardID as WardID
FROM LL_WardItems_Details wdDtl
WHERE isposted = 0
GROUP BY wdDtl.ItemID,WardItemDtl_ID,ReceivedWardID,WardTransID
ORDER BY WardItemDtl_ID )
, PartyItemsDtl AS ( SELECT WardItemDtl_ID,
ItemID,
SUM(IssueItemQty) IssueItemQty
FROM LL_PartyItems_Details
GROUP BY WardItemDtl_ID,ItemID
ORDER BY WardItemDtl_ID )
SELECT wdDt.WardTransID,
wdDt.ItemID,
itmt.ItemCode,
itmt.ItemDescription,
wdDt.ItemQty as TotalItemQty,
NVL(pDtl.IssueItemQty, 0) as IssueQtyToParty,
wdDt.WardID,
wdmt.Ward_Name
from WardItemsDtl wdDt,PartyItemsDtl pDtl
inner join LLItemMst itmt
on itmt.ItemID=wdDt.ItemID -----error in this line
inner join ward_mst wdmt -- error in this line
on wdmt.Ward_ID=wdDt.WardID
error
Error report:
SQL Error: ORA-00904: "WDDT"."ITEMID": invalid identifier
00904. 00000 - "%s: invalid identifier"
*Cause:
*Action:WITH WARDITEMSDTL AS
(SELECT WARDITEMDTL_ID,
WARDTRANSID,
WDDTL.ITEMID,
SUM(ITEMQTY) ITEMQTY,
RECEIVEDWARDID AS WARDID
FROM LL_WARDITEMS_DETAILS WDDTL
WHERE ISPOSTED = 0
GROUP BY WDDTL.ITEMID,
WARDITEMDTL_ID,
RECEIVEDWARDID,
WARDTRANSID
ORDER BY WARDITEMDTL_ID
PARTYITEMSDTL AS
(SELECT WARDITEMDTL_ID,
ITEMID,
SUM(ISSUEITEMQTY) ISSUEITEMQTY
FROM LL_PARTYITEMS_DETAILS
GROUP BY WARDITEMDTL_ID,
ITEMID
ORDER BY WARDITEMDTL_ID
SELECT WDDT.WARDTRANSID,
WDDT.ITEMID,
ITMT.ITEMCODE,
ITMT.ITEMDESCRIPTION,
WDDT.ITEMQTY AS TOTALITEMQTY,
NVL(PDTL.ISSUEITEMQTY, 0) AS ISSUEQTYTOPARTY,
WDDT.WARDID,
WDMT.WARD_NAME
FROM WARDITEMSDTL WDDT,
PARTYITEMSDTL PDTL,
LLITEMMST ITMT,
WARD_MST WDMT
WHERE ITMT.ITEMID=WDDT.ITEMID
AND WDMT.WARD_ID=WDDT.WARDID ;AND WHERE YOUR JOIN PARTYITEMSDTL PDTL -
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...). -
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, -
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.
ThanksI 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 -
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 -
With clause within the cursor ???
Hello gurus,
Can we have a with clause within the cursor ???
something like this ..
cursor test_cur is
WITH unpivoted_data AS
SELECT DISTINCT
f.cust_id
f.office_cd
f.type_cd
FROM refoff ro,
cutomer p,
office f
WHERE f.cust_id = p.cust_id
AND f.office_cd = ro.office_cd
AND f.type_cd IN ('ACCT', 'pay')
SELECT cust_id
, MAX (CASE WHEN type_cd = 'ACCT' THEN office_id END) AS acct_office_id
, MAX (CASE WHEN type_cd = 'pay' THEN office_id END) AS pay_office_id
FROM unpivoted_data
GROUP BY cust_id
test_cur_rec test_cur% rowtype;
Begin
for test_cur_rec in test_cur
loop
insert into test1 (.....) values (.......);
end loop;
end;
One more quick question .... How do u guys past in the posting ??? Like somesought of a box .....I have seen lot senior gurus when they are replying, they post the code in some sought of a box ....that makes very easy to understand and take look at the code in the posting....???
Thank you so much!!!Hi,
user642297 wrote:
Hello gurus,
Can we have a with clause within the cursor ???Sure, but don't take my word for it. Try it and see!
If you get an error, post the error message.
If you get unexpected results, explain.
Whenever you have a problem, post your full Oracle version number.
One more quick question .... How do u guys past in the posting ??? Like somesought of a box .....I have seen lot senior gurus when they are replying, they post the code in some sought of a box ....that makes very easy to understand and take look at the code in the posting....??? Type these 6 characters:
(all small letters, inside curly brackets) before and after formatted sections. -
With clause in SQL query data model
Hello!
isn't it possible to use the with clause in sql query data models?
for example following query:
WITH
a_test as (
select dummy from dual
select *
from a_test
brings up a "XML Parsing Error: no element found"-error...
BR PaulI tried a slightly different query (see below) and the query worked fine and retrieved data.. I did not get any errors.
WITH
a_test as (
select 'dummy' from dual
select *
from a_test
This works as well.. retrieving the value of the parameter
WITH
a_test as (
select :Test_ID from dual
select *
from a_test
thanks,
BIPuser
Maybe you are looking for
-
I-pod cannot update because all the playlists selected for no longer exsist
What does this mean?? I have tons of songs on my itunes, but now I have 0 on my ipod and can't figure out how to transfer them. THis is a new problem, they used to transfer just fine...HELP
-
Can I use higher watt charger for my ipad?
My ipad came with 10w charger. the ipad takes 4 hours for 100% charge. Can I use higher watt charger to charge my ipad. Will it void the warranty? and I can i use my ipad while charging?
-
Dear experts, In which table the standard cost estimate values will be stored? plz help me. Regards jay
-
Owners custom field source in Project Server 2013
Hi, I have two PWA environment. The users are synced using AD. The permission mode used is SharePoint permission mode. I have a user who is not getting listed in the Owners field(out of box field) in one environment. The user is added on to the PWA o
-
Why is there still loss of data connection on a NEW Driod 4?
Got my NEWDriod 4 on or about the 14th of march,2012, tried phone for 1 day charged over night and no data signal. Whats up with that ? called tech and they said I needed a new phone. recieved a refurb, and I having that ! should I cancel my NEW con