存储过程 返回游标类型

测试环境:oracle9i

 

存储过程:

 

create or replace procedure getEmpByDept(
  out_curEmp out SYS_REFCURSOR
)
is
begin
  open out_curEmp for
       SELECT * FROM aa01;
exception
when others then
     RAISE_APPLICATION_ERROR(-20101,'Error in getEmpByDept' || SQLCODE );
end getEmpByDept;

 

打印

SQL> var result refcursor
SQL> begin
  2  getEmpByDept(:result);
  3  end;
  4  /

PL/SQL 过程已成功完成。

SQL> print :result;

 

注意:在sqlplus下用没问题,在PL/SQL下申明var result refcursor是会报错。

你可能感兴趣的:(sql)