PL/SQL (MOSC)
MOSC Banner

How can I setup a function to return a ref cursor that references an existing cursor?

edited Jan 23, 2015 10:01AM in PL/SQL (MOSC) 5 commentsAnswered

Hi there,

I am trying to create a database function/procedure that returns a ref cursor that will reference an existing cursor. For example,

CREATE or replace PACKAGE MyLib AS

TYPE curTyp IS REF CURSOR;

function GetCursor(curNum INT) return curTyp;

END MyLib;

/

CREATE or replace PACKAGE BODY MyLib AS

cursor c1 is select * from dept;

cursor c2 is select * from emp;

function GetCursor(curNum INT) return curTyp IS

myCur curTyp;

BEGIN

   -- This doesn't work, but how can I make it work?

   if curNum = 1 then

      OPEN myCur FOR c1;

   else

      OPEN myCur for c2;

   end if;

return myCur;

END;

Howdy, Stranger!

Log In

To view full details, sign in to My Oracle Support Community.

Register

Don't have a My Oracle Support Community account? Click here to get started.

Category Leaderboard

Top contributors this month

New to My Oracle Support Community? Visit our Welcome Center

MOSC Help Center