Home » SQL & PL/SQL » SQL & PL/SQL » Re: How to get the primary key value from a new inserted record?
Re: How to get the primary key value from a new inserted record? [message #2169] Tue, 25 June 2002 22:19
Todd Barry
Messages: 4819
Registered: August 2001
Senior Member
If you are on 8i or later, you can use the returning clause. Assume the primary key column in the parent is named pk_col and the value for this column is assigned using a sequence in a trigger so we don't refer to pk_col in the insert statement. This is a PL/SQL example where v_pk_col is a variable that will hold the value of pk_col:

insert into parent (non_pk_col1, non_pk_col2) values ('some', 'data')
  returning pk_col into v_pk_col;
 
insert into child (fk_reference_to_parent, non_pk_col3) values (v_pk_col, 'other');
Previous Topic: Re: SERVICE NAME
Next Topic: Trigger sequence problem
Goto Forum:
  


Current Time: Thu Apr 25 08:41:34 CDT 2024