4

有人可以解释一下如何使用 EclipseLink 调用存储过程吗?这是我的存储过程:

TYPE nested_varchar2 IS TABLE OF varchar2(15);
TYPE nested_number IS TABLE OF number(1);

 procedure set_pacs_state_cond(
    icond in varchar2, -- where condition
    icheck_state in number, -- check expected current state
    iso_id_list out nested_varchar2, -- list of suboperators
    ipac_list out nested_varchar2, -- list of pacs
    iresult out nested_number -- list of results
);

我使用 EclipseLink 2.4.1 作为 JPA 实现。请在下面查看我的代码。

PLSQLStoredProcedureCall call = new PLSQLStoredProcedureCall();

call.setProcedureName("PCK_PR.set_pacs_state_cond");

call.addNamedArgument("icond", "icond", Types.VARCHAR);
call.addNamedArgument("icheck_state", "icheck_state", Types.NUMERIC);
call.addNamedOutputArgument("iso_id_list", "iso_id_list", Types.ARRAY, "nested_varchar2");
call.addNamedOutputArgument("ipac_list", "ipac_list", Types.ARRAY, "nested_varchar2");
call.addNamedOutputArgument("iresult","iresult", Types.ARRAY, "nested_number");

DataModifyQuery valQuery = new DataModifyQuery();
valQuery.setCall(call);

valQuery.addArgument("icond");
valQuery.addArgument("icheck_state");
valQuery.addArgument("iso_id_list", java.sql.Array.class);
valQuery.addArgument("ipac_list", java.sql.Array.class);
valQuery.addArgument("iresult", java.sql.Array.class);

List test1 = new ArrayList();
List test2 = new ArrayList();
List test3 = new ArrayList();

valQuery.addArgumentValue("WHERE");
valQuery.addArgumentValue(1);
valQuery.addArgumentValue(test1);
valQuery.addArgumentValue(test2);
valQuery.addArgumentValue(test3);

session.executeQuery(valQuery);

List results = (List) session.executeQuery(valQuery);

em.getTransaction().commit();

DatabaseRecord record = (DatabaseRecord)results.get(0);

List ii = (List) record.get("iso_id_list");
List i = (List) record.get("ipac_list");
List r = (List) record.get("iresult");

em.close();

我收到以下错误:

Internal Exception: java.sql.SQLException: ORA-06550: line 5, column 21:
PLS-00201: identifier 'ARRAY' must be declared
ORA-06550: line 5, column 21:
4

1 回答 1

3

不能通过 JDBC 返回 PLSQL TABLE 类型。PLSQLStoredProcedureCall 的工作方式是将 TABLE 类型与 VARRAY 类型包装在一起。您需要自己创建镜像 VARRAY 类型,并指定它们。这是一个或测试之一的示例,

    PLSQLCollection collection = new PLSQLCollection();
    collection.setTypeName("PLSQL_P.PLSQL_CITY_LIST");
    collection.setCompatibleType("PLSQL_P_PLSQL_CITY_LIST");
    collection.setNestedType(JDBCTypes.VARCHAR_TYPE);

    PLSQLStoredProcedureCall call = new PLSQLStoredProcedureCall();
    call.setProcedureName("PLSQL_P.PLSQL_CITY_LIST_IN");
    call.addNamedArgument("P_CITY_LIST", collection);
    call.addNamedArgument("P_CITY", JDBCTypes.VARCHAR_TYPE);
    DataModifyQuery query = new DataModifyQuery();
    query.addArgument("P_CITY_LIST", java.sql.Array.class);
    query.addArgument("P_CITY", String.class);
    query.setCall(call);
于 2013-04-17T14:15:05.047 回答