CREATE OR REPLACE TRIGGER DTULTATU_OPER
BEFORE INSERT OR UPDATE OR DELETE
ON OPERADOR FOR EACH ROW
BEGIN
   IF DELETING THEN
      INSERT INTO DELETECACHE (NMTABLECACHE, CDFILICACHE, DSKEYCACHE, DTULTATUCACH)
                       VALUES ('OPERADOR', '', 'CDOPERADOR='||:OLD.CDOPERADOR||';', SYSDATE);
   ELSE
      IF INSERTING THEN
         :NEW.DTULTATUOPER := SYSDATE;
      ELSE
         IF NVL(:OLD.CDOPERADOR, 0)   <> NVL(:NEW.CDOPERADOR, 0) OR
            NVL(:OLD.NMOPERADOR, 0)   <> NVL(:NEW.NMOPERADOR, 0) OR
            NVL(:OLD.NMACESSO, 0)     <> NVL(:NEW.NMACESSO, 0)   OR
            NVL(:OLD.CDSENHOPER, 0)   <> NVL(:NEW.CDSENHOPER, 0) OR
            NVL(:OLD.DSEMAILOPER, 0)  <> NVL(:NEW.DSEMAILOPER, 0)OR
            NVL(:OLD.CDFUNC, 0)  <> NVL(:NEW.CDFUNC, 0)OR
            NVL(:OLD.IDOPERATIVO, 0)  <> NVL(:NEW.IDOPERATIVO, 0)OR
            NVL(:OLD.CDCARGO, 0)  <> NVL(:NEW.CDCARGO, 0)OR
            NVL(:OLD.CDSETOR, 0)  <> NVL(:NEW.CDSETOR, 0)OR
            NVL(:OLD.NRRAMALOPER, 0)  <> NVL(:NEW.NRRAMALOPER, 0)OR
            NVL(:OLD.IDSTATUSENHA, 0) <> NVL(:NEW.IDSTATUSENHA, 0)OR
            NVL(:OLD.CDSENEMAILOP, 0) <> NVL(:NEW.CDSENEMAILOP, 0)OR
	    NVL(:OLD.DIGIOPERADOR, 0) <> NVL(:NEW.DIGIOPERADOR, 0) THEN
            :NEW.DTULTATUOPER := SYSDATE;
         END IF;
      END IF;
   END IF;
END;
/


ALTER TABLE OPERADOR MODIFY DTULTATUOPER DEFAULT SYSDATE
/

UPDATE OPERADOR SET DTULTATUOPER = SYSDATE WHERE DTULTATUOPER IS NULL
/