I would like to do something like this
CREATE OR REPLACE FUNCTION return_cursor RETURN SYS_REFCURSOR IS
CURSOR theCursor IS
SELECT 1
FROM dual;
myCursor SYS_REFCURSOR;
BEGIN
OPEN myCursor for theCursor;
RETURN myCursor;
END return_cursor;
Is there a way to do this?, the reason I want this is because I have some cursor defined at a global scope in a package, and wouldn’t like to re-write them for the call of a function.
I know, i could just delete the global cursor and always use the function, but I still want to know if this is possible. Thanks.
a pl/sql cursor and refcursor are not interchangable, so no you cannot do what you want directly like that.
one option would be to use a view instead, i.e.
then in your package just select from the view wherever the cursor was used. i.e. instead of
write
and for the refcursor
that way you don’t have to rewrite the view SQL for this one case.