Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Re: Address last rows in a table
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 - 17:47:03 CST