CREATE OR REPLACE TRIGGER DTULTATU_LOCALDELIVER
BEFORE INSERT OR UPDATE OR DELETE
ON LOCALDELIVER FOR EACH ROW

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

ALTER TABLE LOCALDELIVER MODIFY DTULTATULDEL DEFAULT SYSDATE
/

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

