How to use Execute Immediate to execute a procedure and return a cursor?
503171Nov 16 2006 — edited Nov 21 2006The procedure name is unknown until run time so I have to use Execute immediate to execute the procedure, the procedure return a cursor, but I can't figure out the right syntax to pass the cursor out.
To simplify the issue here, I create two procedures as examples.Assume I have a procedure called XDTest:
(
p_cur OUT SYS_REFCURSOR
)
IS
BEGIN
OPEN p_cur FOR
Select * from dummy_table;
END XDTest;
In another procedure, I want to use Execute Immediate to execute XDTest and obtain the result that return from the cursor into a local cursor so I can process the records:
(
p_cur OUT SYS_REFCURSOR
)
IS
l_cur SYS_REFCURSOR;
BEGIN
execute immediate 'BEGIN XDTest (:1); END;' using OUT l_cur;
END XDTest2;
However, this is not working, I get ORA-03113: end-of-file on communication channel error.
What syntax should I use here?
Cheers