一、创建包
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;
本文介绍了一个简单的PL/SQL包及其实现过程,包括包的创建、包体的编写以及如何通过一个具体的例子来调用包中的过程。示例中演示了如何定义一个返回员工记录集的游标类型,并通过一个过程获取这些记录。
255

被折叠的 条评论
为什么被折叠?



