如何在Oracle触发器中使用查询语句
通常情况下,Oracle数据库禁止在行级触发器或行级触发器所调用的子程序中使用查询语句。但是,面对复杂的业务逻辑,不可避免的要使用查询语句。 当在行级触发器中使用查询语句时,Oracle数据库会抛出ORA-04091异常。 Oracle官方文档中对ORA-04091异常的说明如下: ORA-04091: table string. string 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. 如果必须要在Trigger中使用查询语句,Oracle也提供了一种途径。 下面以简单的代码为例做说明: 1 CREATE OR REPLACE TRIGGER TRG_TEST 2 BEFORE INSERT OR UPDATE OR DELETE ON SCOTT.EMP 3 FOR EACH ROW -- 行级触发器 4 DECLARE 5