2012年3月5日星期一

Oracle Ref Cursor 示例


--如这个存储过程,该如何接收外部的一个变量进来?
create or replace procedure pro_show_emp(
       empno_in in scott.emp.empno%type,--在要传进来的参数后面加上一个关键字in
       cv_emp in out sys_refcursor
       )
is
begin
     open cv_emp for
     select * from scott.emp emp
     where emp.empno=empno_in;
     
     exception
     when others then
          dbms_output.put_line(sqlerrm);
end pro_show_emp;
/
SQL>  variable x refcursor;--refcursor:sqlplus下运行
SQL>  exec pro_show_emp(7788,:x);
PL/SQL procedure successfully completed.
SQL>  print x;


     EMPNO ENAME      JOB              MGR HIREDATE              SAL       COMM     DEPTNO
---------- ---------- --------- ---------- -------------- ---------- ---------- ----------
      7788 SCOTT      ANALYST         7566 19-4月 -87           3100                    20

没有评论:

发表评论