0

I am trying to create a trigger that audits two fields when they are updated in a table. I have tried compiling the PL/SQL, but the following error keeps coming up.

ORA-04079: invalid trigger specification

Referring to other SO questions they mention using Declare or As to solve this problem

CREATE OR REPLACE TRIGGER AUDIT_TRIGGER
BEFORE UPDATE OF MR_STATE, IS_EXEMPT
ON CX_MR mr
FOR EACH ROW
BEGIN
     IF UPDATING ('MR_STATE') THEN 
          INSERT INTO CX_AUDIT
          (
          INT_ID,
          FIELD_NAME,
          OLD_VAL,
          NEW_VAL,
          CHANGED_DATE,
          CHANGED_BY
          )
          VALUES
          (
          mr.INTEGRATION_ID,
          'MR_STATE',
          :old.MR_STATE,
          :new.MR_STATE,
          SYSDATE,
          'Trigger'
          );
     END IF;

    IF UPDATING ('IS_EXEMPT') THEN 
          INSERT INTO CX_AUDIT
          (
          INT_ID,
          FIELD_NAME,
          OLD_VAL,
          NEW_VAL,
          CHANGED_DATE,
          CHANGED_BY
          )
          VALUES
          (
          mr.INT_ID,
          'IS_EXEMPT',
          :old.IS_EXEMPT,
          :new.IS_EXEMPT,
          SYSDATE,
          'Multiroom'
          );
     END IF;
END;

However I am not sure what I should be declaring or if this is the solution.

4

1 回答 1

1

错误似乎是您在 table name 后面有一个额外的标记“mr” CX_MR。您不能在触发器定义中为表名设置别名。

然后,您似乎继续尝试在触发器主体中使用别名。mr删除“mr”标记后,触发器的标头应该可以编译,但在INSERT语句中使用时会出现编译错误。不过,我不确定我是否理解您在那里尝试做的事情......您似乎知道如何使用:new:old伪记录来获取旧值和新值。我的猜测是你只想要:new.int_id两个INSERT语句中的。但我不清楚您是否出于某种原因避免使用该结构,以及您是否希望mr.int_id有所不同。

于 2013-10-28T16:20:44.577 回答