2014-11-05 35 views
0

FORALL插入花更多的時間來插入時遇到了在應用程序的支付表中只有4000行..有什麼辦法可以優化我的代碼FORALL插入花更多的時間來插入

DECLARE 
    TYPE PAY_TAB_REC IS RECORD (
     PAYMENT_ID   NUMBER, 
     PAYMENT_TYPE_ID  NUMBER, 
     AMOUNT    NUMBER, 
     PAYMENT_DATE   DATE, 
     CREATED_DATE   DATE, 
     CREATED_BY   NUMBER, 
     PAYMENT_RECEIPT_NO VARCHAR2 (20), 
     MODIFIED_BY   NUMBER, 
     MODIFIED_DATE  DATE, 
     PAYEE_ID    NUMBER (10), 
     PAYER_ID    NUMBER (10), 
     IS_URGENT   NUMBER (1) DEFAULT 0, 
     APP_ID    NUMBER 
    ); 

    TYPE PAY_TAB_TYPE IS TABLE OF PAY_TAB_REC 
     INDEX BY PLS_INTEGER; 

    PAY_TAB PAY_TAB_TYPE; 

    CURSOR C_APP 
    IS 
     SELECT SEQ_PAYMENT.NEXTVAL PAYMENT_ID, PAYMENT_TYPE_ID, AMOUNT, 
      PAYMENT_DATE, CREATED_DATE, CREATED_BY, PAYMENT_REF_NO, 
      MODIFIED_BY, MODIFIED_DATE, PAYEE_ID, PAYER_ID, IS_URGENT, 
      APP_ID 
     FROM APPLICATION_PAYMENT; 
BEGIN 
    OPEN C_APP; 

    LOOP 
     FETCH C_APP 
     BULK COLLECT INTO PAY_TAB LIMIT 100; 

     FORALL I IN 1 .. PAY_TAB.COUNT 
     INSERT INTO PAYMENT 
       VALUES PAY_TAB (I); 
    END LOOP; 

    CLOSE C_APP; 

    COMMIT; 
END; 

從application_payment表時選擇的價值觀和插入付款表。但它需要更多的時間和循環運行而沒有結束。幫助我在application_payment表中只有78000條記錄。

回答

0

你可以使用,而不是循環

INSERT INTO PAYMENT 
SELECT SEQ_PAYMENT.NEXTVAL PAYMENT_ID, PAYMENT_TYPE_ID, AMOUNT, 
      PAYMENT_DATE, CREATED_DATE, CREATED_BY, PAYMENT_REF_NO, 
      MODIFIED_BY, MODIFIED_DATE, PAYEE_ID, PAYER_ID, IS_URGENT, 
      APP_ID 
     FROM APPLICATION_PAYMENT; 
選擇Insert