我想要调用以下函数:
CREATE OR REPLACE PACKAGE utils AS
TYPE item_list IS TABLE of items.item_id%TYPE;
FUNCTION getParentsForItem(p_item_id IN items.items_id%TYPE)
RETURN item_list;
END utils;
但我不确定如何将java Collection绑定到getParentsForItem的返回类型。
答案 0 :(得分:4)
经过一些Google搜索,我找到了this example。它使用Oracle JDBC驱动程序独有的方法,即:
在适合你的情况之后,也许这会奏效:
警告:我自己没有编译过。
int itemId = ...;
// This feature is only supported by the OCI driver:
Connection connection = DriverManager.getConnection("jdbc:oracle:oci8:@[HOST]", "[USER]", "[PASSWORD]");
CallableStatement callableStatement = connection.prepareCall("{? = utils.getParentsForItem(p_item_id => ?)}");
OracleCallableStatement oracleCallableStatement = (OracleCallableStatement) callableStatement;
int maximumElementsInTable = 150; // the maximum possible number of elements.
int elementSqlType = Types.INTEGER; // index table element SQL type (as defined in java.sql.Types or OracleTypes).
int elementMaxLen = 100; // maximum length of the element. If not specified, maximum length allowed for that type is used.
oracleCallableStatement.registerIndexTableOutParameter(
1,
maximumElementsInTable,
elementSqlType,
elementMaxLen
);
oracleCallableStatement.setInt(2, itemId);
oracleCallableStatement.execute();
int[] parentItemIds = oracleCallableStatement.getPlsqlIndexTable(1);