我在Oracle Express 11g上。我試圖創建此觸發器:創建UPDATE觸發器,導致刪除觸發行
CREATE TRIGGER remove_useless_surveys
BEFORE UPDATE OF agent_id, agency_id, province_id ON surveys
FOR EACH ROW WHEN (
new.agent_id IS NULL AND
new.agency_id IS NULL AND
new.province_id IS NULL)
DELETE FROM surveys WHERE survey_code = :new.survey_code
agent_id,agency_id和province_id是外鍵,帶有ON DELETE SET NULL子句。
當所有三個外鍵都設置爲NULL(因爲引用的行被刪除)時,我需要調查表中的一行被刪除。
觸發編譯沒有問題,但是當條件火災,然後我得到這個錯誤:
SQL error: ORA-04091: table REALESTATE.SURVEYS is mutating,
trigger/function may not see it ORA-06512: at
"REALESTATE.REMOVE_USELESS_SURVEYS", line 1 ORA-04088: error during
execution of trigger 'REALESTATE.REMOVE_USELESS_SURVEYS'
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.
其實,我知道我編輯激發觸發器在同一個表。但是我想取消更新,或者敲定它,我不在意,然後刪除那行。
你能幫我嗎?我怎樣才能實現我想要做的?
可能是語句執行的觸發器或PL/SQL函數。該觸發器/函數試圖修改或查詢觸發器/函數正在修改的表。請檢查http://www.techonthenet.com/oracle/errors/ora04091.php – user1127214 2012-04-10 12:46:33
@ user1127214:是的,這是重點:) – gd1 2012-04-10 12:47:48