【发布时间】:2014-04-23 01:56:20
【问题描述】:
我正在尝试在 oracle 12c 中创建一个触发器,如果插入的值包含特定值,它将执行过程。
我想要做的是在某些表(EVENTS、MARKS、STAGE)全部刷新之后,我才希望触发器运行 REFRESH_MVS();程序。
它们在刷新后存储在 COUNTS 表中。所以我正在检查 COUNTS 中的新 INSERT 是否有关键字:EVENTS、MARKS、STAGE。
这样就可以了吗?
CREATE or replace TRIGGER MV_REFRESH
AFTER INSERT ON COUNTS
FOR EACH ROW
DECLARE
MODEL_NAME varchar2(20);
BEGIN
select MODEL INTO MODEL_NAME from COUNTS;
IF(MODEL_NAME = 'EVENTS' AND MODEL_NAME = 'MARKS' AND MODEL_NAME = 'STAGE')
THEN
REFRESH_MVS();
END IF;
END;
如果我运行INSERT,编译成功后:
INSERT INTO COUNTS
values ('EVENTS', '11658495', '0.11', '17-MAR-14', '17-MAR-14');
它抛出错误:
Error starting at line 3 in command:
INSERT INTO COUNTS
values ('EVENTS', '11658495', '0.11', '17-MAR-17', '17-MAR-17')
Error report:
SQL Error: ORA-04091: table COUNTS is mutating, trigger/function may not see it
ORA-06512: at "MV_REFRESH", line 5
ORA-04088: error during execution of trigger 'MV_REFRESH'
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.
【问题讨论】: