Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.server -> Re: Get the primary key of the last record added
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
![]() |
![]() |