2017-02-22 60 views
0

我是Oracle的新手,並且遇到了從數組中刪除值的問題。我試圖:如果我有一個數組1,2,3,4我想刪除2,一旦數據庫已經處理此數組值,然後移動到3.Oracle刪除數組中的值PL SQL

代碼I'中號使用的是:

type test_rec is record (temp_id number, 
     pos1 number, 
     pos2 number, 
     pos3 number); 

type test_array is table of test_rec index by binary_integer; 

PROCEDURE pr_test (
parv_test IN test_array) 
AS 
BEGIN 
FOR i in parv_test.first .. parv_test.last LOOP 
    IF parv_test(i).action_type = 'I' THEN 
     INSERT STATEMENT 

     parv_test.delete(i); 
    END IF; 
END LOOP; 
END pr_test ; 

但是,我得到的錯誤:

PLS-00363: expression 'parv_test' cannot be used as an assignment target 

有人能告訴我,我要去哪裏錯了嗎?

非常感謝。

乾杯

亞歷

+0

嘗試更改參數定義:'parv_test IN OUT test_array' –

+1

副本parv_test到本地參數,你不能修改輸入參數 –

+0

謝謝,這很好。全部排序現在 –

回答

0

您不能修改輸入參數,

嘗試這樣,

create or replace package body test_pkg is 

    type test_rec is record(temp_id number, 
           pos1 number, 
           pos2 number, 
           pos3 number, 
           action_type varchar2(1)); 

    type test_array is table of test_rec index by binary_integer; 

    PROCEDURE pr_test(parv_test IN test_array) AS parv_test_local test_array; 
BEGIN 
    parv_test_local := parv_test; 
    FOR i in parv_test_local.first .. parv_test_local.last LOOP 
    IF parv_test_local(i).action_type = 'I' THEN 
     --INSERT STATEMENT 

     parv_test_local.delete(i); 
    END IF; 
    END LOOP; 
END pr_test; 

begin 
null; 
end test_pkg; 
+1

非常感謝! –

+0

ü,歡迎:) –