Create or Replace function test111 (ItemNumber in varchar2) return sys_refcursor
is
return_cursor sys_refcursor;
begin
OPEN return_cursor for SELECT ' a ' dual WHERE 1 = itemnumber;
return return_cursor;
End test111;
Use the following SQL to return the cursor, in the PL SQL developer can directly point to open the query results
Select test111 (1) from dual;
Applicable conditions: Can be applied when the SQL statement is too long, avoid having too long SQL code in the Java code.
JDBC Call result set
Package com.dahuatech.job;
Import java.sql.CallableStatement;
Import java.sql.Connection;
Import Java.sql.DriverManager;
Import Oracle.jdbc.driver.OracleResultSet;
Import Oracle.jdbc.driver.OracleTypes;
public class Test {public
static void Main (string[] args) throws Exception {
Class.forName (" Oracle.jdbc.driver.OracleDriver ");
String url = "Jdbc:oracle:thin:@10.30.5.106:1521:agile9";
Connection conn = drivermanager.getconnection (URL, "agile", "* * *");
String sql = "{? = Call test111 (?)}";
CallableStatement CST = conn.preparecall (SQL);
Cst.registeroutparameter (1, oracletypes.cursor);
Cst.setstring (2, "1");
Cst.execute ();
Oracleresultset rs = (Oracleresultset) cst.getobject (1);
while (Rs.next ()) {
System.out.println (rs.getstring ("a"));
}
}
A function of the jdbctemplete call of the SPRINGMVC frame returned as a string
public string Transf (final String Inmodel) {return
Jdbctemplate.execute ("{? = Call Transfmodel (?)} ', new Callablestatementcallback<string> () {
@Override public
String Doincallablestatement (CallableStatement cs)
throws SQLException, DataAccessException {
Cs.registeroutparameter (1, Oracletypes.varchar);
Cs.setstring (2, Inmodel);
Cs.execute ();
Return (String) cs.getobject (1);}}
);