Oracle中的存储过程在pl/sql和java中如何调用

Linux大全评论231 views阅读模式

案例:添加学生,然后返回该班级的所有学生。

create or replace procedure add_stu(
p_sid stu.sid%type,        
p_sname stu.sname%type,
p_cid stu.cid%type,
p_data out sys_refcursor     -- 输出变量,系统引用游标
)
as
begin
   insert into stu(sid,sname,cid)
   values(p_sid,p_sname,p_cid);
   commit;
 
   --将查询的结果集的地址放到引用游标变量中,再传递出去
   open p_data for select * from stu where cid=p_cid;
 
end;

--PL/SQL 调用
declare
  stu_data sys_refcursor;
  stu_row stu%rowtype;
begin
  add_stu(52,'b',1,stu_data);
  fetch stu_data into stu_row;
  while(stu_data%found)
  loop
     dbms_output.put_line(stu_row.sname);
     fetch stu_data into stu_row;
  end loop;
  close stu_data;
end;

企鹅博客
  • 本文由 发表于 2020年9月20日 17:57:15
  • 转载请务必保留本文链接:https://www.qieseo.com/149175.html

发表评论