CREATE OR REPLACE TRIGGER DTULTATU_ENDECONS
BEFORE INSERT OR UPDATE OR DELETE
ON ENDECONS FOR EACH ROW
BEGIN
   IF INSERTING THEN
      :NEW.DTULTATU := SYSDATE;
   END IF;
   IF UPDATING THEN
      IF (NVL(:OLD.DSENDECONS,0) <> NVL(:NEW.DSENDECONS,0))   OR
         (NVL(:OLD.NRENDECONS,0) <> NVL(:NEW.NRENDECONS,0))   OR
         (NVL(:OLD.NRCEPCONS,0 ) <> NVL(:NEW.NRCEPCONS,0))    OR
         (NVL(:OLD.CDPAIS,0    ) <> NVL(:NEW.CDPAIS,0))       OR
         (NVL(:OLD.SGESTADO,0  ) <> NVL(:NEW.SGESTADO,0))     OR
         (NVL(:OLD.CDMUNICIPIO,0) <> NVL(:NEW.CDMUNICIPIO,0)) OR
         (NVL(:OLD.CDBAIRRO,0   ) <> NVL(:NEW.CDBAIRRO,0))    OR
         (NVL(:OLD.DSCOMPLENDECONS,0) <> NVL(:NEW.DSCOMPLENDECONS,0)) OR
         (NVL(:OLD.DSREFERENDECONS,0) <> NVL(:NEW.DSREFERENDECONS,0)) OR 
         (NVL(:OLD.NMQUADRANTECONS,0) <> NVL(:NEW.NMQUADRANTECONS,0)) THEN
         :NEW.DTULTATU := SYSDATE;
      END IF;
   END IF;
   IF DELETING THEN
      INSERT INTO DELETECACHE (NMTABLECACHE, CDFILICACHE, DSKEYCACHE, DTULTATUCACH)
                       VALUES ('ENDECONS', '', 'CDCLIENTE='||:OLD.CDCLIENTE||';CDCONSUMIDOR='||:OLD.CDCONSUMIDOR||';CDENDECONS='||:OLD.CDENDECONS||';', SYSDATE);
   END IF;   
END;

/