CREATE OR REPLACE TRIGGER DTULTATU_CTRLNUMEDELI
BEFORE INSERT OR UPDATE OR DELETE
ON CTRLNUMEDELI FOR EACH ROW

BEGIN
   IF INSERTING THEN
      :NEW.DTULTATUCDEL := SYSDATE;
   END IF;
   IF UPDATING THEN
      IF (NVL(:OLD.CDCTRLNUMDEL,0) <> NVL(:NEW.CDCTRLNUMDEL,0)) OR
         (NVL(:OLD.NMCTRLNUMDEL,0) <> NVL(:NEW.NMCTRLNUMDEL,0)) OR
         (NVL(:OLD.CDFILIAL    ,0) <> NVL(:NEW.CDFILIAL    ,0)) OR
         (NVL(:OLD.DTULTATUCDEL,TO_DATE('31/12/1899','DD/MM/YYYY')) <>  NVL(:NEW.DTULTATUCDEL,TO_DATE('31/12/1899','DD/MM/YYYY'))) THEN
         :NEW.DTULTATUCDEL := SYSDATE;
      END IF;
   END IF;
   IF DELETING THEN
      INSERT INTO DELETECACHE (NMTABLECACHE, CDFILICACHE, DSKEYCACHE, DTULTATUCACH)
                       VALUES ('CTRLNUMEDELI', '', 'CDCTRLNUMDEL='||:OLD.CDCTRLNUMDEL||';', SYSDATE);
   END IF;
END;
/

ALTER TABLE CTRLNUMEDELI MODIFY DTULTATUCDEL DEFAULT SYSDATE
/

-- VERSAO --
BEGIN ATUVEROBJ('DTULTATU_CTRLNUMEDELI','4.11.027'); END;
/

