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

Home -> Community -> Usenet -> c.d.o.tools -> Re: selecting last inserted record in table

Re: selecting last inserted record in table

From: neil <n-h_u-l_i-n_at_my-deja.com>
Date: Fri, 08 Dec 2000 01:37:49 GMT
Message-ID: <3a303a29.1952607@news.fuse.net>

This technique cannot be relied upon to return the last row. You need to consider row chaining and block reuse. The ROWID psuedo column is a map of the physical location of the data. If a row migrates, it's ROWID changes.

One reliable way to address this is to add an ID column populated from a sequence using a trigger. The rows can then be returned based on the sequence number in the ID field. This will give you the rows in the order that the sequence was generated which might not be the order that they were committed in, depending on the application. In all but very specific cases it should be sufficient.

...neil

On Fri, 08 Dec 2000 00:29:08 GMT, faheemrao_at_my-deja.com wrote:

>
>
>I have the problem of my problem
>
>This query would solve the purpose
>
>
>select column_name ,rowid from table_name
>where rowid in( select max(rowid) from table_name)
>
>
>
>Thanks to me :))
>
>
>
>In article <90p70h$a5t$1_at_nnrp1.deja.com>,
> faheemrao_at_my-deja.com wrote:
>>
>>
>> I want to select the last inserted record in a table.
>>
>> I know that there is something to be do with the rownum but when I try
>> this quer logically it seems to be ok , but it is select zero rows,
>>
>> select * from table_name where rownum in (select max(rownum) from gg)
>>
>> to me that the subquery return the rownum 1 and that is why actuall
>> query goiving no result , I want a solution in one quer if posssible
 if
>> not I can go for stored procedure.
>>
>> thanks
>>
>> Faheem Rao
>>
>> Sent via Deja.com http://www.deja.com/
>> Before you buy.
>>
>
>
>Sent via Deja.com http://www.deja.com/
>Before you buy.
  Received on Thu Dec 07 2000 - 19:37:49 CST

Original text of this message

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