Oracle SQL mutating table trigger before update

156 Views Asked by At

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.

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. Any Suggestion ? Thanks

1

There are 1 best solutions below

1
On

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;