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

Home -> Community -> Usenet -> c.d.o.server -> Re: Get the primary key of the last record added

Re: Get the primary key of the last record added

From: Allen Kirby <akirby_at_att.com>
Date: 1997/05/06
Message-ID: <336F255E.18CA@att.com>#1/1

Steve McDaniels wrote:
>
> won't this do it?
>
> Query A: select max(rowid) from <table>;
>
> select <keyed field> from <table> where rowid = chartorowid(<rowid from
> query A>);

<snip>

Good guess, but no, it won't work. The rowid contains the file,block and row number of the record. Since rows can be stored in any block with enough free space, there is no way to correlate the physical storage address with the insertion time. You must use a column that increases in value with each insertion, then select max of that column. Sequence numbers or sysdate usually work fine. This can be implemented with triggers, default values or in the application itself.

-- 
---
Allen Kirby			AT&T ITS Production Services
akirby_at_att.com			Alpharetta, GA.
Received on Tue May 06 1997 - 00:00:00 CDT

Original text of this message

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