先创建一个包
create or replace package MYPACKAGE as
--定义包中的游标变量
type empcursor is ref cursor;
--定义包中的方法
procedure queryEmpList(dno in number,empList out empcursor);
end MYPACKAGE;
创建一个包体
--创建一个包体
create or replace package body MYPACKAGE is
--实现包的方法
procedure queryEmpList(dno in number,empList out empcursor) as
begin
--将查询数据封装装入游标
open empList for select * from emp where deptno = dno;
end queryEmpList;
end MYPACKAGE;
pl/sql调用
-- Created on 2018/10/11 by 19135
declare
--定义接收返回值的游标
cue sys_refcursor;
--循环时使用的变量
e emp%rowtype;
begin
--通过包名调用该包下面的方法
MYPACKAGE.queryEmpList(30,cue);
loop
fetch cue
into e;
exit when cue%notfound;
--循环控制台输出游标中的值
dbms_output.put_line(e.ename);
end loop;
end;