I have a PL/SQL stored function which returns a table of integers:
CREATE TYPE INT_TABLE IS TABLE OF INTEGER;
CREATE FUNCTION f (someParam IN INTEGER) RETURN INT_TABLE IS ...
I wish to use JDBC to retrieve the result of this function so that I can iterate through the integers in some way, be it a ResultSet
, int[]
, or whatever.
The function f
performs modifications to the database, so it cannot be called in a query such as SELECT f(42) FROM DUAL;
. The return value exists to inform the caller of the primary keys for the rows that it modified. I presumably must use a CallableStatement
, but can't figure out exactly how. Taking inspiration from here, I have tried:
CallableStatement cs = conn.prepareCall("{? = call f(42)}");
cs.registerOutParameter(1, Types.ARRAY);
cs.execute();
ResultSet rs = cs.getArray(1).getResultSet();
However, this resulted in java.sql.SQLException: Invalid argument(s) in call
on the registerOutParameter
line. I haven't been able to determine what this error actually means, as the docs are quite general on the exceptions that may be thrown.
I've spent hours googling and am at quite a loss as to how to proceed. Is it possible to extract a table type into Java? If not, is there some other way of returning multiple integers from the PL/SQL function that can be extracted into Java?