以下是我的pl \ sql和java用法:
PL \ SQL:
procedure getDetails(id in number,
varArray out var_array,
valArray out var_array,
anotherArray out var_array,
description out varchar2 )
type var_array IS table of VARCHAR2(255) index by BINARY_INTEGER;
爪哇:
CallableStatement cstmt = (OracleCallableStatement) conn.prepareCall("{call pkg.getDetails(?,?,?,?,?)}");
cstmt.setInt(1, Integer.parseInt(resultList.get(0).trim()));
cstmt.registerOutParameter(2, oracle.jdbc.OracleTypes.ARRAY);
cstmt.registerOutParameter(3, oracle.jdbc.OracleTypes.ARRAY);
cstmt.registerOutParameter(4, oracle.jdbc.OracleTypes.ARRAY);
cstmt.registerOutParameter(5, oracle.jdbc.OracleTypes.VARCHAR);
cstmt.execute();
我在执行电话时收到错误:
java.sql.SQLException:ORA-06550:第1行第7列: PLS-00306:调用'GETDETAILS'
时参数的数量或类型错误
答案 0 :(得分:0)
实际上这段代码只需要复制粘贴,您只需要更改自己的程序并定义参数......
String sql = "{call my_own_procedure(?)}";
String[] values = new String[1];
values[0] = "some value";
java.sql.CallableStatement callableStatement = null;
callableStatement = myOracleConnection.prepareCall(sql);
if (values != null) {
for (int parameterIndex = 0; parameterIndex < values.length; parameterIndex++) {
callableStatement.setString(parameterIndex + 1, values[parameterIndex]);
}
}
result = callableStatement.executeUpdate();
不要忘记使用SQL异常并导入SQL包......