Home » SQL & PL/SQL » SQL & PL/SQL » RE: Return an inserted row value from within a stored procedure
RE: Return an inserted row value from within a stored procedure [message #2460] Wed, 17 July 2002 21:26 Go to next message
Nuralain Khuda
Messages: 1
Registered: July 2002
Junior Member
Hi,

I have a stored procedure that inserts a new record to a table each time it executes and uses an oracle sequence generated number for the primary key. I would like to retrieve the Primary Key number for the record immediately after it's inserted to the table before the stored procedure executes again. Is it possible to to have the stored procedure return the PK value for the record immediately following the insert? Any help would be appreciated!

Thanks,

Nuralain
Re: RE: Return an inserted row value from within a stored procedure [message #2461 is a reply to message #2460] Wed, 17 July 2002 22:13 Go to previous message
Todd Barry
Messages: 4819
Registered: August 2001
Senior Member
Sure, just use the RETURNING clause of the INSERT statement:

create or replace procedure do_insert
  (p_in_data in number, p_pk_value out number)
is
begin
  -- pk column is populated via a sequence in a trigger
  insert
    into t (non_pk_column)
    values (p_in_data)
    returning pk_column into p_pk_value;
end;
Previous Topic: please any one help me
Next Topic: Error while connecting to oracle
Goto Forum:
  


Current Time: Fri Apr 26 09:43:54 CDT 2024