【发布时间】:2017-02-16 08:07:38
【问题描述】:
我的桌子
产品(P_name,new_price,old_price);
我想创建一个触发器,如果 new_price 被更新,那么 old_price 应该用之前的 new_price 更新。
SET SERVEROUTPUT ON;
CREATE OR REPLACE TRIGGER update_old_price
AFTER UPDATE ON product
FOR EACH ROW
BEGIN
UPDATE product SET old_price = :old.new_price
WHERE product_name=:old.product_name;
END;
但它显示错误
Error report -
SQL Error: ORA-04091: table MANIKIRAN.KODAM.PRODUCT is mutating, trigger/function may not see it
ORA-06512: at "MANIKIRAN.KODAM.UPDATE_OLD_PRICE", line 5
ORA-04088: error during execution of trigger 'MANIKIRAN.KODAM.UPDATE_OLD_PRICE'
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.
所以请给我一个解决方案。
【问题讨论】:
标签: sql oracle11g triggers oracle-sqldeveloper