Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Re: Doubt about cursors
Oswaldo Castro wrote:
> Hi Folks,
>
> I have the following code im pl/sql in a procedure:
>
> -------------------------------
> AS CURSOR c1 is
> select
> cod_1
> , cod_2
> from
> some_table
> where
> cod_1 <> 0
> order by
> cod_1, cod_2
> ;
> r1 c1%rowtype;
> counting number(5);
> cod_1_previous number(5);
>
> BEGIN
> open c1;
> loop
> fetch c1 into r1;
> exit when c1%notfound;
> counting := 1;
> cod_1_previous := r1.cod_1;
> while cod_1_previous = r1.cod_1
> loop
> DBMS_OUTPUT.PUT_LINE('Rec = '||r1.cod_1||'-'||r1.code_2||'-'||counting);
> counting := counting + 1;
> fetch c1 into r1;
> end loop;
> end loop;
> close c1;
> end;
>
> -------------------------
>
> My doubt is:
>
> Is this the best construction considering that I need to call FETCH inside the loop?
> Is there a better way?
>
> Thanks to everyone in advance.
>
> Oswaldo Castro
Assuming a supported version of Oracle: No. There is no excuse for using cursor loops given their poor performance.
http://www.psoug.org
click on Morgan's Library
click on Bulk Binding/Bulk Collection
The purpose of the inner loop escapes me.
-- Daniel A. Morgan University of Washington damorgan_at_x.washington.edu (replace 'x' with 'u' to respond)Received on Sun Apr 17 2005 - 12:14:57 CDT