設萬維讀者為首頁 萬維讀者網 -- 全球華人的精神家園 廣告服務 聯繫我們 關於萬維
 
首  頁 新  聞 視  頻 博  客 論  壇 分類廣告 購  物
搜索>> 發表日誌 控制面板 個人相冊 給我留言
幫助 退出
江南風的博客  
江南風的博客  
https://blog.creaders.net/u/3799/ > 複製 > 收藏本頁
網絡日誌正文
Trigger: the mutating table error ORA-04091 2010-05-12 08:39:15
I got "the mutating table error ORA-04091" when I tested one of my triggers. This is because I queried the table that fires the trigger.

Here's the example, which involves 3 tables, table1 (columns: report_id, process_id,...), table2 (columns: process_id, organisation, ...), and table3 (columns: organisation, bu, ...).

create or replace trigger ci_updated_trig

  AFTER UPDATE  OF UPDATE_DTTM
  ON TABLE1
  FOR EACH ROW
DECLARE
  -- local variables here
  v_exist  NUMBER;
  v_is_wanted_ci NUMBER;
BEGIN
  -- check if this is wanted record
  SELECT COUNT(*) INTO v_is_wanted_ci
    FROM table1 t1, table2 t2, table3 t3
   WHERE t1.report_id = :new.report_id AND t1.process_id = t2.process_id AND
         t2.organisation = t3.organisation AND t3.bu='ES';

   ...... ......        
END ;

If should be corrected into the following:

create or replace trigger ci_updated_trig
  AFTER UPDATE  OF UPDATE_DTTM
  ON TABLE1
  FOR EACH ROW
DECLARE
  -- local variables here
  v_exist  NUMBER;
  v_is_wanted_ci NUMBER;
BEGIN
  -- check if this is wanted record
  SELECT COUNT(*) INTO v_is_wanted_ci
    FROM table2 t2, table3 t3
   WHERE t2.process_id = :new.process_id AND
         t2.organisation = t3.organisation AND t3.bu='ES';

   ...... ......        
END ;


瀏覽(647) (0) 評論(0)
發表評論
我的名片
江南風
註冊日期: 2010-05-12
訪問總量: 4,774 次
點擊查看我的個人資料
Calendar
最新發布
· ORA-06553: PLS-382: expression
· Trigger: the mutating table er
分類目錄
【報稅點滴】
【Database Tips】
· ORA-06553: PLS-382: expression
· Trigger: the mutating table er
存檔目錄
2010-05-12 - 2010-05-13
 
關於本站 | 廣告服務 | 聯繫我們 | 招聘信息 | 網站導航 | 隱私保護
Copyright (C) 1998-2025. Creaders.NET. All Rights Reserved.