I don't think that you have provided the exact content of your session here, otherwise you wouldn't have managed to create the second version of your function without compilation error as there is no return statement.
So long as ref_cursor has been declared by a TYPE statement inside your PL/SQL, I don't see any problem in using it as the returned type of your function. Here is a similar example by using the hr.employees sample table:
--
set serveroutput on
--
<<bk1>>
declare
type ref_cursor is ref cursor;
--
fname hr.employees.first_name%type;
empCur sys_refcursor;
--
function testFun
(
p_depid in hr.employees.department_id%type
)
return ref_cursor
is
begin
<<bk2>>
declare
empCur sys_refcursor;
begin
open
bk2.empCur
for
select
t1.first_name
from
hr.employees t1
where
t1.department_id = p_depid;
--
--
return bk2.empCur;
end;
end testFun;
begin
bk1.empCur := bk1.testFun(p_depid => 100);
--
loop
fetch
bk1.empCur
into
bk1.fname;
--
exit when bk1.empCur%notfound;
--
sys.dbms_output.put_line('fname = ' || bk1.fname);
end loop;
--
close bk1.empCur;
end;
/
--
show errors;
--
set serveroutput off
And the output
No errors.
fname = Nancy
fname = Daniel
fname = John
fname = Ismael
fname = Jose Manuel
fname = Luis
PL/SQL procedure successfully completed.
SQL>