有人可以解释一下如何使用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:
答案 0 :(得分:2)
PLSQL TABLE类型不能通过JDBC返回。 PLSQLStoredProcedureCall的工作方式是使用VARRAY类型包装TABLE类型。您需要创建镜像VARRAY类型yourslef,并指定它们。以下是其中一个或测试的示例
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);