简体   繁体   English

更新前的Oracle SQL变异表触发器

[英]Oracle SQL mutating table trigger before update

I want to create an update trigger for a table. 我想为表创建一个更新触发器。 The trigger was created, but when I update the column finish , it say mutating table. 触发器已创建,但是当我更新finish列时,它说了变异表。

This is my code 这是我的代码

    CREATE OR REPLACE TRIGGER SET_COST BEFORE UPDATE OF finish ON PAY
    FOR EACH ROW

    BEGIN

    UPDATE PAY
    SET PAY.COST = (finish-start) * 20000
    WHERE PAY.ID=:new.ID;

    END;

This trigger gives me 'Mutating Table' error and so far I have been unable to fix it. 此触发器给我“ Mutating Table”错误,到目前为止,我无法修复它。 Any Suggestion ? 有什么建议吗? Thanks 谢谢

First of all, you shouldn't be doing that at all. 首先,您根本不应该这样做。 There's no use in storing values that are easily calculated whenever you need them. 存储需要时轻松计算的值没有用。

As of your question: no UPDATE: 关于您的问题:没有更新:

begin
  :new.cost := (:new.finish - :new.start) * 20000;
end;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM