返回结果集的存储过程实例及调用

来源:互联网 发布:12345数字打字软件 编辑:程序博客网 时间:2024/05/22 08:03

1、创建一个包,定义一个游标类型,为存储过程的输出参数使用

create or replace package sp_emp_pk astype sp_emp_cursor is ref cursor;end sp_emp_pk;/

2、创建返回结果集的存储过程

create or replace PROCEDURE sproc_cursor(deptnum in number,emp_cursor out sp_emp_pk.sp_emp_cursor) isbeginopen emp_cursor for select ename,sal from emp where deptno=deptnum;end sproc_cursor;/

3、返回结果集的存储过程的调用

declare type sp_emp_cursor is ref cursor;emp_cursor sp_emp_cursor;--v_empno emp.empno%type:=7839;v_deptno emp.deptno%type:=10;v_ename emp.ename%type;v_sal emp.sal%type;beginsproc_cursor(v_deptno,emp_cursor);loopfetch emp_cursor into v_ename,v_sal;exit when emp_cursor%notfound;--sp_pro8(v_empno,v_ename);dbms_output.put_line(v_ename);end loop;--dbms_output.put_line('Hello world');close emp_cursor;end;/
0 0
原创粉丝点击