CREATE OR REPLACE TRIGGER DTULTATU_RECETPCARD
BEFORE INSERT OR UPDATE OR DELETE
ON RECETPCARD FOR EACH ROW

DECLARE
V_CDPRATO      RECETPCARD.CDPRATO%TYPE;
V_CDFILAUXPRAT RECETPCARD.CDFILAUXPRAT%TYPE;

BEGIN
   IF DELETING THEN
      V_CDPRATO      := :OLD.CDPRATO;
      V_CDFILAUXPRAT := :OLD.CDFILAUXPRAT;
   ELSE
      V_CDPRATO      := :NEW.CDPRATO;
      V_CDFILAUXPRAT := :NEW.CDFILAUXPRAT;
   END IF;

   UPDATE
      PRATO
   SET
      DTULTATURECE = SYSDATE
   WHERE
      (CDPRATO      = V_CDPRATO) AND
      (CDFILAUXPRAT = V_CDFILAUXPRAT);
      
   IF (NOT DELETING) THEN
      :NEW.DTULTATURECPTP := SYSDATE;
   END IF;
END;
/