I'm not sure if I'm understanding the concept of a Dynamic Cursor, but I was trying to do the following:
Oracle: 10.2G
The following is a skeleton of my stored procedure
--Variables
xVar1 := pVar1;
xVar2 := pVar2;
--Cursor
CURSOR xCursor (pVar1,pVar2) IS
SELECT temp1.column1, temp1.column2,temp1.column3, temp2.dat, dyn.dpt1, dyn.dp2, etc...
FROM (select column1, column2, column3, etc...
from xtable
) temp1,
('select || 'xVar1' || as dpt1, || 'xVar2' || as dpt2, etc..'
from xtable2
) dynt
WHERE join subqueries....
TYPE Curs_Array IS TABLE OF xCursor %ROWTYPE INDEX BY PLS_INTEGER;
ca Curs_Array ;
IF xVar = 1 THEN
pVar1 := 'anything';
ELSIF xVar = 2 THEN
pVar2 :='something';
ELSE
null
END IF;
--Actual Program
OPEN xCursor (pVar1,pVar2);
FETCH xCursor BULK COLLECT INTO ca ;
CLOSE xCursor ;
FOR ii IN 1 .. ca.COUNT LOOP
-- output variable array data
END LOOP;
END;
With the code above I get a invalid table name error (where the dynamic sql begins in the cursor) when I try to compile the procedure.
Is there a simple fix to my issue or am I simply not using dyanmic sql properly?
Edited by: user652714 on Jul 22, 2010 12:04 PM