Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to use Execute Immediate to execute a procedure and return a cursor?

503171Nov 16 2006 — edited Nov 21 2006
The 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
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 19 2006
Added on Nov 16 2006
26 comments
3,398 views