CREATE OR REPLACE TRIGGER DTULTATU_COMESERVTCAR
BEFORE INSERT OR UPDATE OR DELETE
ON COMESERVTCAR FOR EACH ROW

BEGIN
   IF INSERTING THEN
      :NEW.DTULTATUCSTC := SYSDATE;
   END IF;
   IF UPDATING THEN
      IF (NVL(:OLD.QTCOMPMESEG,0) <> NVL(:NEW.QTCOMPMESEG,0)) OR
         (NVL(:OLD.QTCOMPMETER,0) <> NVL(:NEW.QTCOMPMETER,0)) OR
         (NVL(:OLD.QTCOMPMEQUA,0) <> NVL(:NEW.QTCOMPMEQUA,0)) OR
         (NVL(:OLD.QTCOMPMEQUI,0) <> NVL(:NEW.QTCOMPMEQUI,0)) OR
         (NVL(:OLD.QTCOMPMESEX,0) <> NVL(:NEW.QTCOMPMESEX,0)) OR
         (NVL(:OLD.QTCOMPMESAB,0) <> NVL(:NEW.QTCOMPMESAB,0)) OR
         (NVL(:OLD.QTCOMPMEDOM,0) <> NVL(:NEW.QTCOMPMEDOM,0)) OR
         (NVL(:OLD.QTCOMPMEFER,0) <> NVL(:NEW.QTCOMPMEFER,0)) OR
         (NVL(:OLD.QTCLIPMESEG,0) <> NVL(:NEW.QTCLIPMESEG,0)) OR
         (NVL(:OLD.QTCLIPMETER,0) <> NVL(:NEW.QTCLIPMETER,0)) OR
         (NVL(:OLD.QTCLIPMEQUA,0) <> NVL(:NEW.QTCLIPMEQUA,0)) OR
         (NVL(:OLD.QTCLIPMEQUI,0) <> NVL(:NEW.QTCLIPMEQUI,0)) OR
         (NVL(:OLD.QTCLIPMESEX,0) <> NVL(:NEW.QTCLIPMESEX,0)) OR
         (NVL(:OLD.QTCLIPMESAB,0) <> NVL(:NEW.QTCLIPMESAB,0)) OR
         (NVL(:OLD.QTCLIPMEDOM,0) <> NVL(:NEW.QTCLIPMEDOM,0)) OR
         (NVL(:OLD.QTCLIPMEFER,0) <> NVL(:NEW.QTCLIPMEFER,0)) OR
         (NVL(:OLD.QTFUNPMESEG,0) <> NVL(:NEW.QTFUNPMESEG,0)) OR
         (NVL(:OLD.QTFUNPMETER,0) <> NVL(:NEW.QTFUNPMETER,0)) OR
         (NVL(:OLD.QTFUNPMEQUA,0) <> NVL(:NEW.QTFUNPMEQUA,0)) OR
         (NVL(:OLD.QTFUNPMEQUI,0) <> NVL(:NEW.QTFUNPMEQUI,0)) OR
         (NVL(:OLD.QTFUNPMESEX,0) <> NVL(:NEW.QTFUNPMESEX,0)) OR
         (NVL(:OLD.QTFUNPMESAB,0) <> NVL(:NEW.QTFUNPMESAB,0)) OR
         (NVL(:OLD.QTFUNPMEDOM,0) <> NVL(:NEW.QTFUNPMEDOM,0)) OR
         (NVL(:OLD.QTFUNPMEFER,0) <> NVL(:NEW.QTFUNPMEFER,0)) OR
         (NVL(:OLD.QTDOAPMESEG,0) <> NVL(:NEW.QTDOAPMESEG,0)) OR
         (NVL(:OLD.QTDOAPMETER,0) <> NVL(:NEW.QTDOAPMETER,0)) OR
         (NVL(:OLD.QTDOAPMEQUA,0) <> NVL(:NEW.QTDOAPMEQUA,0)) OR
         (NVL(:OLD.QTDOAPMEQUI,0) <> NVL(:NEW.QTDOAPMEQUI,0)) OR
         (NVL(:OLD.QTDOAPMESEX,0) <> NVL(:NEW.QTDOAPMESEX,0)) OR
         (NVL(:OLD.QTDOAPMESAB,0) <> NVL(:NEW.QTDOAPMESAB,0)) OR
         (NVL(:OLD.QTDOAPMEDOM,0) <> NVL(:NEW.QTDOAPMEDOM,0)) OR
         (NVL(:OLD.QTDOAPMEFER,0) <> NVL(:NEW.QTDOAPMEFER,0)) THEN
         :NEW.DTULTATUCSTC := SYSDATE;
      END IF;
   END IF;
   IF DELETING THEN
      INSERT INTO DELETECACHE (NMTABLECACHE, CDFILICACHE, DSKEYCACHE, DTULTATUCACH)
                       VALUES ('COMESERVTCAR', '', 'CDFILCENTPME='||:OLD.CDFILCENTPME||';CDTIPOCARD='||:OLD.CDTIPOCARD||';CDSERVFILI='||:OLD.CDSERVFILI||';CDFILIAL='||:OLD.CDFILIAL||';', SYSDATE);
   END IF;
END;
/

ALTER TABLE COMESERVTCAR MODIFY DTULTATUCSTC DEFAULT SYSDATE
/