ORA-04091: table 正在变异,trigger/function 可能看不到它 ORA-06512

ORA-04091: table is mutating, trigger/function may not see it ORA-06512

当在另一个 table 上进行插入时,我创建了一个触发器以在 table 中插入日志。

这是触发器的代码:

CREATE OR REPLACE TRIGGER scheme1.Inserting_Feed 
          AFTER INSERT ON scheme2.payments FOR EACH ROW
BEGIN
  INSERT INTO scheme2.db-logger(ID, TECHNOLOGY, WORKFLOW, NAME_EVENT, TIME_EVENT)
  VALUES(:NEW.id,'Repository','UP',(select repo.name 
                                      from scheme1.repository repo 
                                      join scheme2.payments pay 
                                        on repo.id = pay.repository_id
                                     where repo.id = NEW.repository_id), SYSDATE);
END;

我尝试 运行 这个触发器,但是当我插入 table 付款时,我收到以下错误:

Error MT101-GENERAL_LOAD_ERROR: java.sql.SQLSyntaxErrorException: ORA-04091: table scheme1.payments is mutating, trigger/function may not see it ORA-06512: at "scheme1.Inserting_Feed", line 2 ORA-04088: error during execution of trigger 'scheme1.Inserting_Feed'

据我了解,错误提示 table 正在更改,但触发器没有看到它。这是怎么来的?

为什么在insert语句的子查询中join到scheme2.paymentstable?难道你不能这样做:

CREATE OR REPLACE TRIGGER scheme1.inserting_feed
  AFTER INSERT
  ON scheme2.payments
  FOR EACH ROW
BEGIN
  INSERT INTO scheme2.db_logger (id,
                                 technology,
                                 workflow,
                                 name_event,
                                 time_event)
    VALUES      ( :new.id,
                  'Repository',
                  'UP',
                  (SELECT repo.name
                   FROM   scheme1.repository repo
                   WHERE  repo.id = :new.repository_id),
                  SYSDATE);
END;
/