首页 > 数据库 > Oracle > 正文

如何在oracle存储过程中返回游标

2024-08-29 13:33:17
字体:
来源:转载
供稿:网友
1:首先你需要创建一个包,并定义你返回的游标的类型、存储过程create or replace package TEST_PKG is
 
  -- Public type declarations
  type cur_emp is REF CURSOR;
 
  PRocedure test_proc (v_empno in number, emps out cur_emp);
 
end TEST_PKG;2:然后你再创建包体create or replace package body TEST_PKG isprocedure test_proc (v_empno in number, emps out cur_emp)
as
begin
open emps for select * from emp where empno=7369;
end test_proc; 
end TEST_PKG ;3,通过java调用cstmt = conn.prepareCall("{call TEST_PKG .test_proc (?)}");
cstmt.registerOutParameter(1, OracleTypes.CURSOR);
cstmt.execute();
 
//获得结果集
rs = (ResultSet)cstmt.getObject(4);
while(rs.next()){......}

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表