1, process definition (package, cursor, process)
------------The top return is a record, but returns more than one record to use the following--------------------
--1: The process of returning a result set, in which the Test_cursor cursor
is defined The Create or replace package testpackage as
type test_cursor is ref cursor;--defines a test_cursor end
testpackage;
--2: Creating process Create
or replace procedure sp_pro13
(Spno in Number,p_cursor out testpackage.test_cursor)
is Begin
Open P_cursor for SELECT * from EMP where deptno=spno;
End;
--3: in Java when calling
2,java-End Calls
Class.forName (driver);
Conn=drivermanager.getconnection (strURL, "Scott", "Tiger");
CallableStatement Pro =conn.preparecall ("{Call Sp_pro13 (?,?)}");
Pro.setint (1);
There is a cursor variable
pro.registeroutparameter (2, Oracle.jdbc.OracleTypes.CURSOR);
Pro.execute ();
ResultSet rset= (ResultSet) Pro.getobject (2);
while (Rset.next ()) {
System.out.println (rset.getstring (8) + "--->" +rset.getstring (1) + "--->" + Rset.getstring (2)); }
Rset.close ();
Pro.close ();
Conn.close ();
3 results:
--->7499--->allen
--->7521--->ward
--->7654--->martin
--->7698--- >blake
--->7844--->turner
--->7900--->james