CREATE OR REPLACE TRIGGER INSERT_TMPITEMAUTFDEL
AFTER DELETE ON ITEMAUTF FOR EACH ROW
DECLARE
BEGIN
   IF DELETING THEN
      UPDATE TMP_ITEMAUTFDEL
         SET QTPROGENTAF = :OLD.QTPROGENTAF,
             VRPREUNIAF  = :OLD.VRPREUNIAF
       WHERE CDFILDEST   = :OLD.CDFILDEST
         AND CDFILLANC   = :OLD.CDFILLANC
         AND NRAUTOFORN  = :OLD.NRAUTOFORN
         AND CDMARCA     = :OLD.CDMARCA
         AND CDPRODUTO   = :OLD.CDPRODUTO
         AND DTPROGENTAF = :OLD.DTPROGENTAF;
      IF SQL%ROWCOUNT = 0 THEN
         INSERT INTO TMP_ITEMAUTFDEL (NRITEMAUTFDEL,
                                      CDFILDEST,
                                      CDFILLANC,
                                      NRAUTOFORN,
                                      CDMARCA,
                                      CDPRODUTO,
                                      DTPROGENTAF,
                                      QTPROGENTAF,
                                      VRPREUNIAF)
                              VALUES (SEQ_TMPITEMAUTFDEL.NEXTVAL, 
                                      :OLD.CDFILDEST,
                                      :OLD.CDFILLANC,
                                      :OLD.NRAUTOFORN,
                                      :OLD.CDMARCA,
                                      :OLD.CDPRODUTO,
                                      :OLD.DTPROGENTAF,
                                      :OLD.QTPROGENTAF,
                                      :OLD.VRPREUNIAF);
      END IF;
   END IF;
END;
/ 