Dibawah ini contoh Oracle function dan procedure yang menghasilkan curson
create or replace package types as
type cursorType is ref cursor;
end;
/
create or replace function sp_ListEmp return types.cursortype as
l_cursor types.cursorType;
begin
open l_cursor for select ename, empno from emp order by ename;
return l_cursor;
end;
/
create or replace procedure getemps( p_cursor in out types.cursorType ) as
begin
open p_cursor for select ename, empno from emp order by ename;
end;
/
Penggunaan pada program Java-nya seperti ini:
java.sql.Connection conn = null;
...
String query = "begin :1 := sp_listEmp; end;";
CallableStatement cstmt = conn.prepareCall(query);
cstmt.registerOutParameter(1,OracleTypes.CURSOR);
cstmt.execute();
ResultSet rset = (ResultSet)cstmt.getObject(1);
Referensi: http://asktom.oracle.com/~tkyte/ResultSets/
No comments:
Post a Comment