收藏到:
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()){......}