This was originally a view, but based on huge tables and a very long runtime I created these cursors which increase speed from 4 minutes to 7 seconds. Everything runs well. I need to return the values of the last cursor. I am able to use a PACKAGE / PACKAGE BODY as a REF CURSOR with one cursor. However, I am unable to do so with multiple cursors as in the c_maxdate. Can anyone provide me some insight?
I did think about place the values of the c_maxdate into a temp table then returning those values, but I do not know how to do this by running all three cursors....
===============================================
DECLARE
---------------------------------------
-----------GETS EQNUM's BASED ON EQNUM OF RIDESTATUS
---------------------------------------
---------------------------------------
--This works and take 7 seconds to run in production - JMH20040630
--
--
CURSOR c_ridestatus IS
SELECT e.eqnum as eqnum
FROM EQUIPMENT e
--, PARENT, children, LEVEL, description
WHERE LEVEL > 1
--START WITH eqnum = '116082'
START WITH eqnum IN (SELECT s.eqnum FROM maxmeter.WDW_RIDESTATUS s)
CONNECT BY PRIOR eqnum = PARENT;
--
--
CURSOR c_jpnum(i_ridestatus IN equipment.eqnum%type) IS
Select distinct nvl(w.jpnum, p.jpnum) as jpnum, w.pmnum as pmnum, w.eqnum as eqnum
From workorder w, pm p, pmsequence ps, eqhistory h
Where w.pmnum = p.pmnum and
w.eqnum = i_ridestatus and
w.status in ('INPRG', 'WSCH', 'WAPPR', 'WMATL', 'APPR') and
w.wolo3 = 'L' and
w.woeq4 >= 0 and
w.eqnum = h.eqnum and
w.jpnum = ps.jpnum;
--
--
--CREATED INDEX WORKORDER_NDX_JOHN(PMNUM, STATUS)
CURSOR c_maxdate(i_eqnum IN workorder.eqnum%type, p_pmnum IN workorder.pmnum%type) IS
SELECT h.wonum as wonum, h.eqnum as eqnum
FROM eqhistory h, workorder w, pm p
WHERE
p.METERFREQUENCY > 0 and
p.PM3 = 'L' AND
w.pmnum = p.pmnum and
w.eqnum = i_eqnum and
w.STATUS IN ('COMP', 'CLOSE') AND
h.wonum = w.wonum and
w.pmnum = p_pmnum;
---------------------------------------
---------------------------------------
---------------------------------------
---------------------------------------
BEGIN
--
dbms_output.enable(1000000);
--
FOR r_ridestatus IN c_ridestatus
LOOP
--DBMS_OUTPUT.PUT_LINE(r_ridestatus.eqnum);
--
--
FOR r_jpnum IN c_jpnum(r_ridestatus.eqnum)
LOOP
--DBMS_OUTPUT.PUT_LINE(r_jpnum.jpnum||' '||r_jpnum.pmnum||' '||r_jpnum.eqnum);
--
FOR r_maxdate IN c_maxdate(r_jpnum.eqnum, r_jpnum.pmnum)
--
--FOR r_maxdate IN c_maxdate(r_jpnum.pmnum)
LOOP
--DBMS_OUTPUT.PUT_LINE('TEST');
DBMS_OUTPUT.PUT_LINE(r_maxdate.wonum);
END LOOP; --c_maxdate
END LOOP; --c_jpnum
--
--
END LOOP; --c_ridestatus
---------------------------------------
---------------------------------------
END;
================
THANKS
I did think about place the values of the c_maxdate into a temp table then returning those values, but I do not know how to do this by running all three cursors....
===============================================
DECLARE
---------------------------------------
-----------GETS EQNUM's BASED ON EQNUM OF RIDESTATUS
---------------------------------------
---------------------------------------
--This works and take 7 seconds to run in production - JMH20040630
--
--
CURSOR c_ridestatus IS
SELECT e.eqnum as eqnum
FROM EQUIPMENT e
--, PARENT, children, LEVEL, description
WHERE LEVEL > 1
--START WITH eqnum = '116082'
START WITH eqnum IN (SELECT s.eqnum FROM maxmeter.WDW_RIDESTATUS s)
CONNECT BY PRIOR eqnum = PARENT;
--
--
CURSOR c_jpnum(i_ridestatus IN equipment.eqnum%type) IS
Select distinct nvl(w.jpnum, p.jpnum) as jpnum, w.pmnum as pmnum, w.eqnum as eqnum
From workorder w, pm p, pmsequence ps, eqhistory h
Where w.pmnum = p.pmnum and
w.eqnum = i_ridestatus and
w.status in ('INPRG', 'WSCH', 'WAPPR', 'WMATL', 'APPR') and
w.wolo3 = 'L' and
w.woeq4 >= 0 and
w.eqnum = h.eqnum and
w.jpnum = ps.jpnum;
--
--
--CREATED INDEX WORKORDER_NDX_JOHN(PMNUM, STATUS)
CURSOR c_maxdate(i_eqnum IN workorder.eqnum%type, p_pmnum IN workorder.pmnum%type) IS
SELECT h.wonum as wonum, h.eqnum as eqnum
FROM eqhistory h, workorder w, pm p
WHERE
p.METERFREQUENCY > 0 and
p.PM3 = 'L' AND
w.pmnum = p.pmnum and
w.eqnum = i_eqnum and
w.STATUS IN ('COMP', 'CLOSE') AND
h.wonum = w.wonum and
w.pmnum = p_pmnum;
---------------------------------------
---------------------------------------
---------------------------------------
---------------------------------------
BEGIN
--
dbms_output.enable(1000000);
--
FOR r_ridestatus IN c_ridestatus
LOOP
--DBMS_OUTPUT.PUT_LINE(r_ridestatus.eqnum);
--
--
FOR r_jpnum IN c_jpnum(r_ridestatus.eqnum)
LOOP
--DBMS_OUTPUT.PUT_LINE(r_jpnum.jpnum||' '||r_jpnum.pmnum||' '||r_jpnum.eqnum);
--
FOR r_maxdate IN c_maxdate(r_jpnum.eqnum, r_jpnum.pmnum)
--
--FOR r_maxdate IN c_maxdate(r_jpnum.pmnum)
LOOP
--DBMS_OUTPUT.PUT_LINE('TEST');
DBMS_OUTPUT.PUT_LINE(r_maxdate.wonum);
END LOOP; --c_maxdate
END LOOP; --c_jpnum
--
--
END LOOP; --c_ridestatus
---------------------------------------
---------------------------------------
END;
================
THANKS