我想执行存储过程(oracle)的输入-数组的数字从eclipselink。
EntityManager entityManager = entityManagerFactory.createEntityManager();
entityManager.getTransaction().begin();
StoredProcedureCall call = new StoredProcedureCall();
call.setProcedureName("P_TEST2");
ReadQuery mquery = new DataReadQuery();
call.addNamedArgument("x");
call.addNamedOutputArgument("z");
mquery.setCall(call);
int [] x = {1,2,3};
Query query = ((JpaEntityManager)entityManager.getDelegate()).createQuery(mquery)
.setParameter("x", x);
DatabaseRecord record = (DatabaseRecord) query.getSingleResult();
System.out.println(record.get("z"));
过程本身
create or replace procedure p_test2(
x in numeric_array,
z out numeric
)
AS
BEGIN
FOR i IN x.first .. x.last
LOOP
INSERT INTO TEST2(ID,VALUE) VALUES (SEQ1.nextval,i);
END LOOP;
commit;
z := seq1.currval;
END;
/
但是它有问题,我认为是数组的问题。
需要你的帮助
就这样解决了:
- 写入函数/过程,接受字符串(以空格或逗号分隔的数组)
- 在函数中解析参数并将其转换为数字(或任何所需类型)表
- 调用所需函数
- 返回需要的结果