Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Re: Counter rows in cursor using for loop.
It would be interesting to hear why you need to take this sort of approach. Having said that, I suggest a cursor loop, with a cursor%rowtype variable.
Something roughly like:
declare
cursor C1 is {your select statement}
prev_row c1%rowtype
first_row boolean := true;
begin
for r1 in c1 loop
if first_row then first_row := false; prev_row := r1; else {do something with prev_row} prev_row := r1; end if; {do the special thing with prev_row}
end loop;
end;
--
Jonathan Lewis
Yet another Oracle-related web site: http://www.jlcomp.demon.co.uk
screwbai_at_my-deja.com wrote in message <7tc961$f0n$1_at_nnrp1.deja.com>...
>
>
>I want count the number of rows that a cursor contain. Basically I want
>to do something with the last row in the cursor.
>
>This is what I want to do:
>for rec in cur
>LOOP
>if counter<last
>then
>.......
>else
>.......
>end if;
>counter :=counter + 1;
>END LOOP;
>
>I guess there is no other way to find the value of last than to
>introduce a second cursor for loop.
>
>This is how I want to get to the value of last.
>
>last :=0;
>for rec in cur
>LOOP
>last := last + 1;
>END LOOP;
>
>I am fairly happy with this solution. But would be curious if there is
>one that would be more elegant.
>
>Thanks !!
>
>
>Sent via Deja.com http://www.deja.com/
>Before you buy.
Received on Tue Oct 05 1999 - 03:05:49 CDT