ORACLE中的数据包的使用

来源:互联网 发布:新青山软件 编辑:程序博客网 时间:2024/05/20 05:28
/*数据包(我们可以把相关的函数,过程,类型,
变量放入一个数据包中,可以实现公共变量,
过程函数对自定义类型的使用)*/
--数据包的说明部分
create or replace package mypack
as
type mytype is ref cursor return emp%rowtype;
function myemp(dno number) return mytype;
end;
/

--数据包的主体部分
create or replace package body mypack
as
function myemp(dno number) return mytype
as
eee mytype;
begin
open eee for select * from emp where deptno=dno;
return eee;
end myemp;
end mypack;
/

--如何调用     数据包名.(方法名/类型名)

declare
e mypack.mytype;
eee emp%rowtype;
begin
e:=mypack.myemp(20);
loop
fetch e into eee;
exit when (e%notfound);
dbms_output.put_line(eee.empno||','||eee.ename||','||eee.job);
end loop;
end;
原创粉丝点击