is
type tcur is ref cursor; --定义返回的结果集
procedure t_p(t_name varchar2 , t_cur out tcur);--定义存储过程
end;
create or replace package body tpk --包体
is
procedure t_p(t_name varchar2 , t_cur out tcur)--存储过程的实现
is
begin
open t_cur for select * from test1 where test1.tname =t_name;--游标记录结果集
end t_p;
end tpk;
CREATE OR REPLACE PROCEDURE userinfo_proc(i_address VARCHAR2, o_cur OUT SYS_REFCURSOR)
IS
sqlstr VARCHAR2(200); -- 定义变量,用以存放SQL语句
BEGIN
sqlstr := 'SELECT Id, Name, Sex, Age, Address FROM userinfo WHERE Address = :i_address'; -- 给SQL变量赋值,其中 :i_address 是绑定变量,以提高执行效率!
OPEN o_cur FOR sqlstr USING i_address; -- 给游标变量赋值
END;
/
set serveroutput on;
var c_cur refcursor;
exec userinfo_proc('北京',:c_cur);
print c_cur;