I am trying to do something similar to the following:
procedure some_name ( p_ref_cursor in out nocopy sys_refcursor )
is
begin
open p_ref_cursor for
select item1, item2 from (some complicated join query);
fetch p_ref_cursor into xx;
if p_ref_cursor%NOTFOUND
then
select item1, item2 from table2 where item3='y';
end if;
end
If the first select statement returns nothing it should execute the second select statement to retrieve values. The problem I am running into is when the cursor is fetched, the result set is cleared out. So regardless if the first select statement found anything, it acts as if it was not found.
I have tried the following:
procedure some_name ( p_ref_cursor in out nocopy sys_refcursor )
is
local_var1 number
local_var2 number
begin
open p_ref_cursor for
select item1, item2
into local_var1, local_var2
from (some complicated join query);
if local_var1 is null
then
select item1, item2 from table2 where item3='y';
end if;
end
However it looks like the INTO statement does not work with ref cursor.
Thanks, Dan