create or replace function fun_emp(prm_choice in number)
return sys_refcursor
is
empcursor sys_refcursor;
begin
if prm_choice=1 then
open empcursor for select * from emp where deptno=10;
elsif prm_choice=2 then
open empcursor for select * from emp where deptno=20;
elsif prm_choice=3 then
open empcursor for select * from emp where deptno=30;
else
open empcursor for select * from emp ;
end if;
return empcursor;
end;
--调用
declare
empcursor sys_refcursor;
rec_emp emp%Rowtype;
begin
empcursor :=fun_emp(10);
if empcursor%isopen then
loop
fetch empcursor into rec_emp;
exit when empcursor%notfound;
dbms_output.put_line(rec_emp.ename);
end loop;
end if;
close empcursor;
end;
return sys_refcursor
is
empcursor sys_refcursor;
begin
if prm_choice=1 then
open empcursor for select * from emp where deptno=10;
elsif prm_choice=2 then
open empcursor for select * from emp where deptno=20;
elsif prm_choice=3 then
open empcursor for select * from emp where deptno=30;
else
open empcursor for select * from emp ;
end if;
return empcursor;
end;
--调用
declare
empcursor sys_refcursor;
rec_emp emp%Rowtype;
begin
empcursor :=fun_emp(10);
if empcursor%isopen then
loop
fetch empcursor into rec_emp;
exit when empcursor%notfound;
dbms_output.put_line(rec_emp.ename);
end loop;
end if;
close empcursor;
end;