CREATE OR REPLACE TRIGGER DTULTATU_ROTFABLOCAL
BEFORE INSERT OR UPDATE OR DELETE
ON ROTFABLOCAL FOR EACH ROW

BEGIN
   IF INSERTING THEN
      :NEW.DTULTATURTFL := SYSDATE;
   END IF;
   IF UPDATING THEN
      IF (NVL(:OLD.CDPRODUTO,0)    <> NVL(:NEW.CDPRODUTO,0))    OR
         (NVL(:OLD.CDSUBPRODLOC,0) <> NVL(:NEW.CDSUBPRODLOC,0)) OR
         (NVL(:OLD.QTSUBPRODLOC,0) <> NVL(:NEW.QTSUBPRODLOC,0)) OR
         (NVL(:OLD.IDIMPPROTLOC,0) <> NVL(:NEW.IDIMPPROTLOC,0)) OR
         (NVL(:OLD.CDFILIAL,0)     <> NVL(:NEW.CDFILIAL,0))     OR
         (NVL(:OLD.DSAPELIDOKDS,0) <> NVL(:NEW.DSAPELIDOKDS,0)) OR
         (NVL(:OLD.DTINIVGPRODLOC,TO_DATE('01/01/0001','DD/MM/YYYY')) <> NVL(:NEW.DTINIVGPRODLOC,TO_DATE('01/01/0001','DD/MM/YYYY'))) OR
         (NVL(:OLD.DTFINVGPRODLOC,TO_DATE('01/01/0001','DD/MM/YYYY')) <> NVL(:NEW.DTFINVGPRODLOC,TO_DATE('01/01/0001','DD/MM/YYYY'))) THEN
         :NEW.DTULTATURTFL := SYSDATE;
         IF NVL(:OLD.CDSUBPRODLOC,0) <> NVL(:NEW.CDSUBPRODLOC, 0) THEN
            INSERT INTO DELETECACHE (NMTABLECACHE, CDFILICACHE, DSKEYCACHE, DTULTATUCACH)
            VALUES ('ROTFABLOCAL', :OLD.CDFILIAL, 'CDFILIAL='||:OLD.CDFILIAL||';CDPRODUTO='||:OLD.CDPRODUTO||';CDSUBPRODLOC='||:OLD.CDSUBPRODLOC||';NRSEQROTFABLOC='||:OLD.NRSEQROTFABLOC||';', SYSDATE);
         END IF;
      END IF;
   END IF;
   IF DELETING THEN
      INSERT INTO DELETECACHE (NMTABLECACHE, CDFILICACHE, DSKEYCACHE, DTULTATUCACH)
                       VALUES ('ROTFABLOCAL', :OLD.CDFILIAL, 'CDFILIAL='||:OLD.CDFILIAL||';CDPRODUTO='||:OLD.CDPRODUTO||';CDSUBPRODLOC='||:OLD.CDSUBPRODLOC||';NRSEQROTFABLOC='||:OLD.NRSEQROTFABLOC||';', SYSDATE);
   END IF;
END;
/

ALTER TABLE ROTFABLOCAL MODIFY DTULTATURTFL DEFAULT SYSDATE
/