Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ORACLE TRIGGER INSERT INTO ... (SELECT * ...)

Trigger with Insert into (select * ...)

I'm trying it.

INSERT INTO T_ USERS SELECT * FROM USERS WHERE ID = :new.ID;

not working...

this work.

INSERT INTO T_USERS(ID) VALUES(:new.ID);

Trigger

create or replace trigger "TRI_USER"
AFTER
insert on "USER"
for each row
begin
INSERT INTO T_USER SELECT * FROM USER WHERE ID = :new.ID;
end;​
like image 331
Eduardo Lynch Araya Avatar asked Feb 18 '26 19:02

Eduardo Lynch Araya


1 Answers

this work.

INSERT INTO T_USERS(ID) VALUES(:new.ID);

So if it fits to you then try this:

INSERT INTO T_USER(ID) SELECT ID FROM USER WHERE ID = :new.ID;

If you want to select one or more rows from another table, you have to use this syntax:

insert into <table>(<col1>,<col2>,...,<coln>)
select <col1>,<col2>,...,<coln>
from ...;
like image 101
Roman Marusyk Avatar answered Feb 21 '26 10:02

Roman Marusyk



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!