在 Java 中,如何从pl/sql
返回数组的函数中获取值。
如果我的 pl/sql 函数返回调用的数组,在 java 中是否可以使用从java 对象myArray
中获取值?myArray
callablestatement
谢谢
更新 1
我在其中调用函数的 Java 代码,但出现异常。
PLS-00306: wrong number or types of arguments in call to 'myfunc'
connection = con.getConnection();
callablestatement = connection.prepareCall("{call myfunc(?,?,?}");
callablestatement.setInt(1, param1);
callablestatement.setInt(2, param2);
callablestatement.setString(3, param3);
callablestatement.registerOutParameter(4, Types.ARRAY);
callablestatement.execute();
resultSet = callablestatement.getArray(4).getResultSet();
更新 2
private final String PRODECURE_NAME = "{? = call myfunc(?,?,?)}";
和
connection = con.getConnection();
callablestatement = connection.prepareCall(PRODECURE_NAME);
callablestatement.registerOutParameter(1, Types.ARRAY);
callablestatement.setInt(2, param1);
callablestatement.setInt(3, param2);
callablestatement.setString(4, param3);
callablestatement.execute();
create or replace type dates
is varray(100) of varchar2(32);
功能
CREATE OR REPLACE function myfunc (
p_id IN number,
p_c_id IN number,
p_co_no IN number
)
RETURN dates
AS
myarray contract_dates;
par1 VARCHAR2 (32);
par2 VARCHAR2 (32);
固定更新 3
connection = con.getConnection();
callablestatement =
connection.prepareCall("begin ? :=myfunc(?,?,?); end;");
callablestatement.registerOutParameter(1, OracleTypes.ARRAY, "DATES");
callablestatement.setInt(2, param1);
callablestatement.setInt(3, param2);
callablestatement.setString(4, param3);
callablestatement.execute();