1

Is there a way to do something like this? Output a cursor's fetched data into a refcursor without stuffing it into a table first?

create or replace procedure someprocedure
(
rc1 in out adv_refcur_pkg.rc)  -- this is defined below
as

v_class_year varchar(10);

cursor c1
is
select distinct e.pref_class_year
from entity e
where e.pref_class_year between i_start_class and i_end_class;

begin
open c1;
loop
fetch c1 into v_class_year;
EXIT WHEN c1%NOTFOUND;

end loop;
close c1;

open rc1 for select v_class_year from dual;
end;

here is the refcursor's declaration

CREATE OR REPLACE PACKAGE ADVANCE.adv_refcur_pkg
AS
TYPE RC IS REF CURSOR;
END adv_refcur_pkg;
1
  • Simply open the rc1 cursor for query used in the c1 cursor definition. Commented Oct 17, 2013 at 13:29

2 Answers 2

1

According with this example, yes, it's possible:

https://forums.oracle.com/thread/696634

Sign up to request clarification or add additional context in comments.

Comments

0

Why go to the trouble of doing that when you can simply pass the cursor itself?

create or replace procedure someprocedure
(
rc1 in out adv_refcur_pkg.rc)  -- this is defined below
as
begin
open rc1 for
   select distinct e.pref_class_year
     from entity e
    where e.pref_class_year between i_start_class and i_end_class;
end;

When you call "someprocedure", you have an open cursor you can then fetch from:

BEGIN
...
  someprocedure(TheCursor);
  LOOP
    fetch TheCursor into v_class_year;
    exit when TheCursor%NOTFOUND;
    ...
  END LOOP;
  CLOSE TheCursor;
...
END;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.