sql - How to create a trigger which, update a row in the same table after insert? -
for example, have table t_1 , insert id
value, trigger should after insert, update value id_2
, set id_2
id
:
create table t_1( id number(10), id_1 number(10) );
i create trigger:
create or replace trigger id_to_id_2 after insert on t_1 each row begin update t_1 set id_2=:new.id id = new.id; end; /
but when try insert, error:
db constraint error: ora-04091: table t_1is mutating, trigger/function may not see it\nora-06512: @
i don't understand error, explain me doing wrong?
you need before insert trigger this:
create or replace trigger id_to_id_2 before insert on t_1 each row begin :new.id_2 := :new.id; end;
Comments
Post a Comment