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 -> Doubt about cursors

Doubt about cursors

From: Oswaldo Castro <ogcastro_at_zaz.com.br>
Date: 17 Apr 2005 08:05:57 -0700
Message-ID: <b3fee624.0504170705.479e481e@posting.google.com>


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 Received on Sun Apr 17 2005 - 10:05:57 CDT

Original text of this message

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