CREATE OR REPLACE TRIGGER DTULTATU_AGENTETERCEFOR
BEFORE INSERT OR UPDATE OR DELETE
ON AGENTETERCEFOR FOR EACH ROW
BEGIN
   IF INSERTING THEN
      :NEW.DTULTATU := SYSDATE;
   END IF;

   IF UPDATING THEN
      IF (NVL(:OLD.CDFILIAL,0)     <> NVL(:NEW.CDFILIAL,0))     OR
         (NVL(:OLD.CDFORNECED,0)   <> NVL(:NEW.CDFORNECED,0))   OR
         (NVL(:OLD.CDALMOXARIFE,0) <> NVL(:NEW.CDALMOXARIFE,0)) OR
         (NVL(:OLD.CDLOCALESTOQ,0) <> NVL(:NEW.CDLOCALESTOQ,0)) THEN
         :NEW.DTULTATU := SYSDATE;
      END IF;
   END IF;

   IF DELETING THEN
      INSERT INTO DELETECACHE (NMTABLECACHE, CDFILICACHE, DSKEYCACHE, DTULTATUCACH)
                       VALUES ('AGENTETERCEFOR', '', 'CDFILIAL='||:OLD.CDFILIAL||';CDFORNECED='||:OLD.CDFORNECED||';', SYSDATE);
   END IF;
END;
/

ALTER TABLE AGENTETERCEFOR MODIFY DTULTATU DEFAULT SYSDATE
/

-- VERSAO --
BEGIN ATUVEROBJ('DTULTATU_AGENTETERCEFOR','5.85.xxx'); END;
/
