触发器问题 - 仅针对最后一行触发

时间:2015-10-23 21:12:41

标签: plsql oracle11g

我有以下触发器定义,问题是它只触发更新的最后一行而不是前一行。

CREATE OR REPLACE TRIGGER APPS.cx_iby_trxn_summary_au
AFTER UPDATE
ON ar.ar_receivable_applications_all
REFERENCING NEW AS NEW OLD AS OLD
FOR EACH ROW
WHEN (
NEW.APPLIED_CUSTOMER_TRX_ID IS NOT NULL AND
NEW.STATUS = 'APP' AND
NEW.DISPLAY = 'Y'
  )
DECLARE 
   vn_cash_receipt_id  NUMBER := -1;  
BEGIN 

insert into cx_log values('Cash Receipt :' || :NEW.RECEIVABLE_APPLICATION_ID);

BEGIN

    SELECT acra.cash_receipt_id
      INTO vn_cash_receipt_id
      FROM ar_cash_receipts_all acra,
           iby_trxn_summaries_all itsa              
     WHERE     acra.cash_receipt_id = :NEW.CASH_RECEIPT_ID
           AND acra.receipt_number LIKE 'IEX_%'
           AND acra.payment_trxn_extension_id IS NOT NULL
           AND itsa.initiator_extension_id = acra.payment_trxn_extension_id
           AND itsa.reqtype = 'ORAPMTREQ'
           AND itsa.instrtype = 'CREDITCARD'
           AND itsa.status = 0;

EXCEPTION
    WHEN NO_DATA_FOUND THEN
        insert into cx_log values('10 NODATAFOUND:' || dbms_utility.format_error_backtrace);
    WHEN OTHERS THEN 
        insert into cx_log values('20 Exception:' || dbms_utility.format_error_backtrace);
END; 


  IF vn_cash_receipt_id > 0 THEN    

   INSERT INTO cx_log values('Cash Receipt ID:' || :NEW.CASH_RECEIPT_ID
    || '--Customer TrxId:' || :NEW.APPLIED_CUSTOMER_TRX_ID
    || '--p_line_amount:' || :NEW.AMOUNT_APPLIED
    || '--p_tax:' || :NEW.TAX_APPLIED
    || '--p_freight:' || :NEW.FREIGHT_APPLIED);

  END IF;

END;
/

Table Structure: 
  ar_cash_receipts_all 
     - ar_receivable_applications_all

问题是当有多行时,只调用一次最后一个insert语句。即使在触发器被触发之前, ar_cash_receipts_all 中的一行应该存在,因为该表是父级,但由于某种原因,以下查询sql未找到“vn_cash_receipt_id”。关于它为什么没有找到第一行的任何想法?

0 个答案:

没有答案