2011-05-12 76 views
1

我遇到了SQL函數的問題,我傳遞了4個NUM_ARRAY類型的參數。我的函數掛在每個FOR循環的WHERE子句中。所以,我不確定如何將我的表格com_umn'edit_id'與我的特定參數進行比較。在SQL函數中對數組進行迭代

CREATE OR REPLACE FUNCTION DEL_BS_INFO (pLfEditDel IN NUM_ARRAY, 
             pRcEditDel IN NUM_ARRAY, 
             pSpnEditDel IN NUM_ARRAY, 
             pComEditDel IN NUM_ARRAY) 
    RETURN NUMBER 
IS 
    tmpVar  NUMBER; 

-- 

BEGIN 
-- If a deletion is checked on the Lost/Found table. 
IF 0 < plfEditDel.COUNT 
THEN 
    FOR i IN plfEditDel.FIRST .. plfEditDel.LAST 
    LOOP 
    UPDATE BSSS 
     SET LOST_FOUND = NULL, 
       LOST_DESC = NULL, 
       LOST_LOC = NULL, 
       LOST_DATE = NULL 
     WHERE EDIT_ID = pLfEditDel; 
    END LOOP; 
END IF; 

-- If a deletion is checked on the Returned Check table. 

IF 0 < pRcEditDel.COUNT 
THEN 
    FOR i IN pRcEditDel.FIRST .. pRcEditDel.LAST 
    LOOP 
    UPDATE XT_BSSS 
     SET RETURN_CHECK = NULL, 
       RETURN_LOC = NULL, 
       RETURN_DATE = NULL 
     WHERE EDIT_ID = pRcEditDel; 
    END LOOP; 
END IF; 

-- If a deletion is checked on the Sponsor table. 

IF 0 < pSpnEditDel.COUNT 
THEN 
    FOR i IN pSpnEditDel.FIRST .. pSpnEditDel.LAST 
    LOOP 
    UPDATE XT_BSSS 
     SET SPONSOR = NULL, 
       SPON_LOC = NULL, 
       SPON_START = NULL, 
       SPON_END = NULL 
     WHERE EDIT_ID = pSpnEditDel; 
    END LOOP; 
END IF; 

-- If a deletion is checked on the Comments table. 

IF 0 < pComEditDel.COUNT 
THEN 
    FOR i IN pComEditDel.FIRST .. pComEditDel.LAST 
    LOOP 
    UPDATE XT_BSSS 
     SET COMMENT = NULL 
     WHERE EDIT_ID = pComEditDel; 
    END LOOP; 
END IF; 

    COMMIT; 
RETURN 0; 
EXCEPTION 
WHEN OTHERS 
THEN 
    ROLLBACK; 
    RETURN SQLCODE; 
END XFW_DEL_BS_INFO; 

回答

3

改變這一點:

WHERE EDIT_ID = pLfEditDel 

這樣:

WHERE EDIT_ID = pLfEditDel(i) 
1

出於性能的考慮,我建議你改變for循環爲FORALL語句,如:

FORALL i IN plfEditDel.FIRST .. plfEditDel.LAST 
UPDATE BSSS 
    SET LOST_FOUND = NULL, 
      LOST_DESC = NULL, 
      LOST_LOC = NULL, 
      LOST_DATE = NULL 
    WHERE EDIT_ID = pLfEditDel(i); 

這將導致一個S.正在執行的QL以及將數組大容量綁定到數據庫 - 而不是您目前獲得的慢速處理。