Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Re: RowID of inserted row

Re: RowID of inserted row

From: Thomas Kyte <tkyte_at_us.oracle.com>
Date: Fri, 22 May 1998 01:08:26 GMT
Message-ID: <3564cf66.1981659@192.86.155.100>


A copy of this was sent to "Scott A. Schell" <saschell_at_lucent.com> (if that email address didn't require changing) On Thu, 21 May 1998 20:59:12 GMT, you wrote:

>Hi,
>
> Is there any way to know what the rowid is of a
>row that has just been inserted -- assume that it's one
>table only i.e.:
>
> insert into table (a, b, c) values (x, y, z)
>
>Can I get the row id for the newly created row?
>
>Please copy me via email also (sometimes it's
>hard to find the news postings).
>
>Thank You in advance
>
>Scott A. Schell
>saschell_at_lucent.com

In O7, the easiest way to get it is via a trigger and package (if you are using O7 oci, the rowid is packed into the cda and you can unpack it but that varies by platform and such).

To get it you would:

create package somePkg
as

    last_rowid rowid;
end;
/

create trigger SomeTrigger
after insert on SomeTable
for each row
begin

   somePkg.last_rowid := :new.rowid;
end;
/

Then you can

insert into T values ( ... );
begin :rid := somePkg.rowid; end;

to get it.

In O8, this simplifies to

insert into T value ( .... ) return rowid into :rid;  

Thomas Kyte
tkyte_at_us.oracle.com
Oracle Government
Herndon VA  

http://govt.us.oracle.com/ -- downloadable utilities  



Opinions are mine and do not necessarily reflect those of Oracle Corporation  

Anti-Anti Spam Msg: if you want an answer emailed to you, you have to make it easy to get email to you. Any bounced email will be treated the same way i treat SPAM-- I delete it. Received on Thu May 21 1998 - 20:08:26 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US