2013-04-04 60 views
1

欲執行與輸入的存儲過程(預言) - 從數的EclipseLink的陣列。的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; 
/

但是有與它的問題,在數組中的問題,我想。

需要你的幫助。

回答

-1

以這種方式解決它:

  1. 寫入功能/過程,接受字符串(陣列由空格或逗號分隔)
  2. 在功能解析參數並將其轉換爲的數字表(或任何需要的型)調用需要
  3. 功能
  4. 回報所需結果