2008年(8065)
分类: 服务器与存储
2008-04-21 12:51:54
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 is
procedure 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,通过调用
cstmt = conn.prepareCall("{call TEST_PKG .test_proc (?)}");
cstmt.registerOutParameter(1, OracleTypes.CURSOR);
cstmt.execute();
//获得结果集
rs = (ResultSet)cstmt.getObject(4);
while(rs.next()){......}