一、创建包
create or replace package PTEST is
type testCursorType is ref cursor;
procedure getTestInfo(testCursor out testCursorType);
end;
二、创建包体
create or replace package body PTEST is
procedure getTestInfo(testCursor out testCursorType) is
begin
open testCursor for
select * from employee;
end;
end;
三、调用测试
注意:不能使用for等隐式游标的调用方法来调用游标变量,因为它已经打开了
declare
mycur ptest.testCursorType;
tid varchar2(10);
tname varchar2(10);
begin
ptest.getTestInfo(mycur);
loop
fetch mycur into tid, tname;
exit when mycur%notfound;
dbms_output.put_line(tid || tname);
end loop;
close mycur;
end;