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

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -