CREATE OR REPLACE TRIGGER DTULTATU_FOPE
BEFORE INSERT OR UPDATE OR DELETE
ON FILIOPER FOR EACH ROW

BEGIN
   IF INSERTING THEN
      :NEW.DTULTATUFOPE := SYSDATE;

      UPDATE OPERADOR
      SET DTULTATUOPER = SYSDATE
      WHERE CDOPERADOR  = :NEW.CDOPERADOR;

      UPDATE OPERGRUPOP
      SET DTULTATUOPGR = SYSDATE
      WHERE CDOPERADOR  = :NEW.CDOPERADOR;
   END IF;
   IF UPDATING THEN
      IF (NVL(:OLD.CDOPERADOR,0) <> NVL(:NEW.CDOPERADOR,0)) OR
         (NVL(:OLD.IDEXIBAVISO,0) <> NVL(:NEW.IDEXIBAVISO,0)) OR
         (NVL(:OLD.CDFILIAL,0)   <> NVL(:NEW.CDFILIAL,0)) THEN
         :NEW.DTULTATUFOPE := SYSDATE;
      END IF;

      UPDATE OPERADOR
      SET DTULTATUOPER = SYSDATE
      WHERE CDOPERADOR  = :OLD.CDOPERADOR;

      UPDATE OPERGRUPOP
      SET DTULTATUOPGR = SYSDATE
      WHERE CDOPERADOR  = :OLD.CDOPERADOR;
   END IF;
   IF DELETING THEN
      INSERT INTO DELETECACHE (NMTABLECACHE, CDFILICACHE, DSKEYCACHE, DTULTATUCACH)
                       VALUES ('FILIOPER', :OLD.CDFILIAL, 'CDOPERADOR='||:OLD.CDOPERADOR||';CDFILIAL='||:OLD.CDFILIAL||';', SYSDATE);
   END IF;
END;
/