Tuesday, September 28, 2010

Oracle - Get the last inserted id how-to

Just simple, declare a variable with that type, mostly number, then   use the 'returning' syntax   for that.

set serveroutput on
declare
 nr_id number;
begin
 insert into employees( id, name, age )
 values( seq_employees.NEXTVAL, 'Jones', 33 )
 returning id into nr_id;
 dbms_output.put_line( 'nr_id = ' || nr_id );
end;
/


Hope this helps. 


- Toytoy Gogie

No comments: