CREATE OR REPLACE TRIGGER DTULTATU_LINHAPROD
BEFORE INSERT OR UPDATE OR DELETE
ON LINHAPROD FOR EACH ROW

BEGIN
   IF INSERTING THEN
      :NEW.DTULTATU := SYSDATE;
   END IF;
   IF UPDATING THEN
      IF (NVL(:OLD.CDLINHAPROD,0     ) <> NVL(:NEW.CDLINHAPROD,0)     ) OR
         (NVL(:OLD.NMLINHAPROD,0     ) <> NVL(:NEW.NMLINHAPROD,0)     ) OR
         (NVL(:OLD.IDLINHAPRINCIPAL,0) <> NVL(:NEW.IDLINHAPRINCIPAL,0)) OR
	     (NVL(:OLD.NRPERCDEMANDA,0   ) <> NVL(:NEW.NRPERCDEMANDA,0)   ) THEN
         :NEW.DTULTATU := SYSDATE;
      END IF;
   END IF;
   IF DELETING THEN
      INSERT INTO DELETECACHE (NMTABLECACHE, CDFILICACHE, DSKEYCACHE, DTULTATUCACH)
                       VALUES ('LINHAPROD', '', 'CDFILIAL='||:OLD.CDFILIAL||';CDLINHAPROD='||:OLD.CDLINHAPROD||';', SYSDATE);
   END IF;
END;

/