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,通过JAVA调用
cstmt = conn.prepareCall("{call TEST_PKG .test_proc (?)}");
cstmt.registerOutParameter(1, OracleTypes.CURSOR);
cstmt.execute();
//获得结果集
rs = (ResultSet)cstmt.getObject(4);
while(rs.next()){......}
本文介绍如何在Oracle中创建包含游标的存储过程,并通过Java进行调用。首先定义了包TEST_PKG及其游标类型和存储过程,接着创建包体实现游标的打开操作,最后演示了使用Java代码调用该存储过程并处理结果集的过程。
3455

被折叠的 条评论
为什么被折叠?



