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: Counter rows in cursor using for loop.

Re: Counter rows in cursor using for loop.

From: Kenneth C Stahl <BlueSax_at_Unforgettable.com>
Date: Tue, 05 Oct 1999 08:38:42 -0400
Message-ID: <37F9F152.691DB7EB@Unforgettable.com>


What about something like this:

declare

    cursor c1 is
    select *
    from emp;
    myrec c1%rowtype;
begin

    dbms_output.enable(1000000);
    for i in c1 loop

        myrec := i;
    end loop;
    dbms_output.put_line('Last Record: EMP='||myrec.empno); end;

When the last record is read, execution will fallout of the loop and the user-defined record 'myrec' will hold the last record retrieved.

screwbai_at_my-deja.com wrote:
>
> 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.

.............................................................
.............................................................
.............................................................
.............................................................
.............................................................
.............................................................
.............................................................
.............................................................
.............................................................
.............................................................
.............................................................
Received on Tue Oct 05 1999 - 07:38:42 CDT

Original text of this message

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