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: Address last rows in a table

Re: Address last rows in a table

From: Marcus Anthony <manthony_at_toast.net>
Date: Thu, 28 Jan 1999 18:29:50 -0600
Message-ID: <36b100d1@news02.>


Theoretically this would work as long as:

rows are inserted in serial
there are no updates on the table
there are no deletes on the table

But I certainly wouldn't rely on it. You must use an order by to insure you get what you want.
Don Hall <dhall_at_twoil.com> wrote in message news:36B0F6F7.610111C1_at_twoil.com...
>You can write a procedure to return the last 10 rows.
>
>declare
>v_row_cnt number := 0;
>v_row_tot number := 0;
>cursor c_your_table is select field1, field2 from your_table;
>begin
>select count(*) into v_row_tot from your_table;
>dbms_output.put_line(' total number of records is '||to_char(v_row_tot));
>for v_row in c_your_table loop
> v_row_cnt := v_row_cnt + 1;
> if v_row_cnt > v_row_tot - 10 then
> dbms_output.put_line('row '||to_char(v_row_cnt)||'
'||v_row.field1||'
>'||v_row.field2);
> end if;
>end loop;
>end;
>
>HTH
>
>
>Miguel Alves wrote:
>
>> Hi,
>>
>> We have a table wich as rows without any sequence (we can't change this
>> because this is an application package) . Our problem is that we have to
>> retrieve the last n rows inserted in the table.
>>
>> Something like the
>>
>> select * from table1 where rownum < 10
>>
>> but for the last 10 rows instead of the first 10.
>>
>> What we realy want is to retrieve the rows using something like a
>> rowtimestamp or sequential rowid. As if the table got a sequence.
>>
>> Thanks in advance,
>> Miguel Alves
>
Received on Thu Jan 28 1999 - 18:29:50 CST

Original text of this message

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