【问题标题】:SQL trigger error reportSQL触发器错误报告
【发布时间】:2015-07-20 00:35:41
【问题描述】:

所以我得到了编写一个触发器的任务,该触发器应该在两列之间交换数据 - LAST_NAME 和 EMAIL 在更新了 SALARY 列的记录中。这就是我想出的

CREATE OR REPLACE TRIGGER SWAP
  FOR UPDATE OF SALARY ON MY_EMP
  COMPOUND TRIGGER
  AFTER EACH ROW IS
    BEGIN
      UPDATE MY_EMP SET LAST_NAME = EMAIL, EMAIL = LAST_NAME WHERE :OLD.SALARY <> :NEW.SALARY;
    END AFTER EACH ROW;
END SWAP;

当我尝试执行此操作时:

UPDATE MY_EMP
SET SALARY = SALARY + 100
WHERE EMPLOYEE_ID = 198;

我收到错误报告:

UPDATE MY_EMP
SET SALARY = SALARY + 100
WHERE EMPLOYEE_ID = 198
Error report -
SQL Error: ORA-04091: table PWR_14_15_L_013209985.MY_EMP is mutating, trigger/function may not see it
ORA-06512: at "PWR_14_15_L_013209985.SWAP", line 4
ORA-04088: error during execution of trigger 'PWR_14_15_L_013209985.SWAP'
04091. 00000 -  "table %s.%s is mutating, trigger/function may not see it"
*Cause:    A trigger (or a user defined plsql function that is referenced in
       this statement) attempted to look at (or modify) a table that was
       in the middle of being modified by the statement which fired it.
*Action:   Rewrite the trigger (or function) so it does not read that table.

我在这里做错了什么?有什么解决办法吗?

【问题讨论】:

  • 错误信息清楚地解释了问题所在。你还想让我们说什么?

标签: sql oracle plsql triggers oracle-sqldeveloper


【解决方案1】:

将其设为更新前,而不是修改基础表,而是修改表的 :new 值。

这将允许您在 DML 提交之前更新这些内容。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-06-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-27
    相关资源
    最近更新 更多