CREATE OR REPLACE TRIGGER DTULTATU_TRANSPORT
BEFORE INSERT OR UPDATE OR DELETE
ON TRANSPORT FOR EACH ROW

BEGIN
   IF INSERTING THEN
      :NEW.DTULTATUTRAN := SYSDATE;
   END IF;
   IF UPDATING THEN
      IF (NVL(:OLD.NMRAZSOCTRAN,0) <> NVL(:NEW.NMRAZSOCTRAN,0)) OR
         (NVL(:OLD.IDTPIJURTRAN,0) <> NVL(:NEW.IDTPIJURTRAN,0)) OR
         (NVL(:OLD.NRINSJURTRAN,0) <> NVL(:NEW.NRINSJURTRAN,0)) OR
         (NVL(:OLD.DSENDETRAN,0)   <> NVL(:NEW.DSENDETRAN,0))   OR
         (NVL(:OLD.SGESTADO,0)     <> NVL(:NEW.SGESTADO,0))     OR
         (NVL(:OLD.NRINSESTTRAN,0) <> NVL(:NEW.NRINSESTTRAN,0)) OR
         (NVL(:OLD.CDPAIS,0)       <> NVL(:NEW.CDPAIS,0))       OR
         (NVL(:OLD.CDMUNICIPIO,0)  <> NVL(:NEW.CDMUNICIPIO,0))  OR
         (NVL(:OLD.CDTIPTRANS,0)   <> NVL(:NEW.CDTIPTRANS,0))   OR
         (NVL(:OLD.NMFANTTRAN,0)   <> NVL(:NEW.NMFANTTRAN,0))   THEN
         :NEW.DTULTATUTRAN := SYSDATE;
      END IF;
   END IF;
   IF DELETING THEN
      INSERT INTO DELETECACHE (NMTABLECACHE, CDFILICACHE, DSKEYCACHE, DTULTATUCACH)
                       VALUES ('TRANSPORT', '', 'IDTPIJURTRAN='||:OLD.IDTPIJURTRAN||';NRINSJURTRAN='||:OLD.NRINSJURTRAN||';', SYSDATE);
   END IF;
END;
/

ALTER TABLE TRANSPORT MODIFY DTULTATUTRAN DEFAULT SYSDATE
/