ORA-04091:表正在变异,触发/功能可能看不到它ORA-06512

时间:2015-04-21 15:46:38

标签: oracle triggers insert

我在另一个表上插入时创建了一个在表中插入日志的触发器。

这是触发器的代码:

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;

我尝试运行此触发器但是当我在桌面付款时插入时出现以下错误:

  

错误MT101-GENERAL_LOAD_ERROR:java.sql.SQLSyntaxErrorException:   ORA-04091:表scheme1.payments是变异的,触发器/函数可以   看不到它ORA-06512:在“scheme1.Inserting_Feed”,第2行ORA-04088:   执行触发器'scheme1.Inserting_Feed'

时出错

我的理解是错误表示表正在改变,但触发器没有看到它。这是怎么来的?

1 个答案:

答案 0 :(得分:3)

为什么要加入insert语句中子查询中的scheme2.payments表?你不能这样做:

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;
/