Skip to Main Content

APEX

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Populating column in one table with a PK from another with a Trigger

MAFinanceDev-OracleNov 18 2015 — edited Nov 18 2015

Hi All,

I’m trying to populate a column on one table with the primary key from a column  on another table that is automatically created when a new row is added.

TABLE_1 automatically generates a primary key called PROJECT_ID when a new row is created. I’ve built a trigger to insert data from TABLE_3 into TABLE_2 when a new row is created on TABLE_1. TABLE_2 also has a column called PROJECT_ID and when the data from TABLE_3 populates TABLE_2, I want the PROJECT_ID on TABLE_2 to match the PROJECT_ID from the newly created row on TABLE_1.

I’m trying to do this with 2 insert into statements but only the first one seems to work. Any advice on how to do this? Thanks!

Here is my code:

create or replace trigger "Trigger_T1"

BEFORE

insert on "TABLE_1"

for each row

begin

insert into TABLE_2

(MILESTONE_DESCRIPTION)

select MILESTONE

from TABLE_3;

insert into TABLE_2

(PROJECT_ID)

select PROJECt_ID

from TABLE_1;

end;

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 16 2015
Added on Nov 18 2015
1 comment
546 views