create table t1(cid int,cname varchar2(100)); insert into t1 values( 1,'3' ); insert into t1 values( 2,'4' ); / ----创建包 create or replace package aaa is type cur is ref cursor; procedure bbb(rst out cur ); procedure ccc; end; / --创建包体 create or replace package body aaa is procedure bbb(rst out cur ) is begin open rst for select * from t1; end; procedure ccc is FRst cur; cid int; cname varchar2(100); begin bbb(FRst); loop fetch FRst into cid,cname; exit when FRst%notfound; dbms_output.put_line( cname ); end loop; end; end;/ --测试 declare i int; begin aaa.ccc; end; / --输出结果 3 4 drop table t1;
insert into t1 values( 1,'3' );
insert into t1 values( 2,'4' );
/
----创建包
create or replace package aaa
is
type cur is ref cursor;
procedure bbb(rst out cur );
procedure ccc;
end;
/
--创建包体
create or replace package body aaa
is
procedure bbb(rst out cur )
is
begin
open rst for select * from t1;
end;
procedure ccc
is
FRst cur;
cid int;
cname varchar2(100);
begin
bbb(FRst);
loop
fetch FRst into cid,cname;
exit when FRst%notfound;
dbms_output.put_line( cname );
end loop;
end;
end;/
--测试
declare
i int;
begin
aaa.ccc;
end;
/
--输出结果
3
4
drop table t1;