Skip to Main Content

SQL & PL/SQL

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!

Get Value from Trigger

Sudhir_MeruJun 14 2012 — edited Jun 14 2012
Hi,

I have two tables table A and table B, Table A has a trigger which inserts ID from trigger, The ID which got inserted from table A has to get also inserted into Table B as a foreign key,

Please find the below script am doing in this method, But I think this may affect some where need some alternative suggestion.

Begin
INSERT INTO A
( NAME, AGE) VALUES ( P_NAME, P_AGE) ;
End;

Note: In the above script ID is automatically inserted through trigger.

Declare
l_a_id number;

Begin

select max(id) into l_a_id from a;

INSERT INTO
( DEPT_NO, DEPT_NAME, A_ID) VALUES ( P_DEPT_NO, l_a_id, P_DEPT_NAME) ;

End;

Please check the above method which am doing is correct or not. If there is any alternative way please suggest me.

Thanks
Sudhir
This post has been answered by vijayrsehgal-Oracle on Jun 14 2012
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 12 2012
Added on Jun 14 2012
8 comments
128 views