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 can I open a cursor for dynamic sql statement

845836Jun 7 2011 — edited Jun 8 2011
Hi,
I'm facing issues opening a cursor for dynamic sql statement : PLS-00455: cursor 'RESULT1' cannot be used in dynamic SQL OPEN statement.

CREATE OR REPLACE FUNCTION DEMO
(MN_I in VARCHAR)
return AB_OWNER.ABC_Type.NonCurTyp is
RESULT1 AB_OWNER.ABC_Type.NonCurTyp;
sql_stmt VARCHAR2(4000);
BEGIN
sql_stmt := 'SELECT * FROM AB_OWNER.DUN WHERE JZ_I in ('||mn_i||') ORDER BY app.ACC_I';
OPEN RESULT1 FOR sql_stmt;
END IF;
return RESULT1;
END DEMO;
/

What changes should I make in the code so that it doesn't fail? I can't change the definition of RESULT1 cursor though.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 6 2011
Added on Jun 7 2011
12 comments
6,029 views