gpt4 book ai didi

jpa - 如何使用 EclipseLink (JPA) 调用 Oracle 存储过程

转载 作者:行者123 更新时间:2023-12-01 20:05:20 28 4
gpt4 key购买 nike

有人可以解释一下如何使用 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:

最佳答案

无法通过 JDBC 返回 PLSQL TABLE 类型。 PLSQLStoredProcedureCall 的工作方式是用 VARRAY 类型包装 TABLE 类型。您需要自己创建镜像 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);

关于jpa - 如何使用 EclipseLink (JPA) 调用 Oracle 存储过程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16062074/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com