构建程序包、

--构建程序包
create or replace package stuinfo as
       type stucur is ref cursor;
       procedure showname(scla in number,stus out stucur);
end stuinfo;
--构建程序包体
create or replace package body stuinfo as 
       procedure showname(scla in number,stus out stucur) as 
         begin 
           open stus for select * from student s where s.class = scla;
         end; 
end stuinfo;
select * from student;

隐式游标

DECLARE

BEGIN
/*
insert
update
delete
select(返回单行的查询)
*/
  UPDATE STUDENT S SET S.SBIRTHDAY = S.SBIRTHDAY + 3650 WHERE s.class=95031;
  IF SQL%FOUND THEN
    DBMS_OUTPUT.PUT_LINE('数据更新成功 !');
    DBMS_OUTPUT.PUT_LINE(sql%ROWCOUNT);
    COMMIT;
  ELSE
    DBMS_OUTPUT.PUT_LINE('更新失败 !');
  END IF;
END;

调用程序包执行存储过程

-- 调用程序包执行存储过程
declare 

  type stuc is ref cursor; --stuc引用游标
  sts stuc;--声明stuc类型的变量
  stu student%rowtype; --每一行查询
  
begin
  stuinfo.showname(95033,sts);
  loop
    fetch sts
          into stu;
    exit when sts%notfound;
    dbms_output.put_line(stu.sname);
  end loop;
  
end;
原文地址:https://www.cnblogs.com/donghb/p/7382244.html