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: loop

Re: loop

From: Piotr Kozlowski <pkozlows_at_tlen.pl>
Date: Sun, 4 Aug 2002 23:21:44 +0200
Message-ID: <aik5t5$118c$1@pingwin.acn.pl>

AFAIK there is another advantage of
for... (select ...) loop
..
end loop;

when an exception occurs and you jump out of the loop in above case, cursor (implicit) will be automatically closed in second one, you have to make sure that you close it.

Piotr

Uzytkownik "Connor McDonald" <connor_mcdonald_at_yahoo.com> napisal w wiadomosci news:3D4D47EE.2142_at_yahoo.com...
> Stjepan Brbot wrote:
> >
> > "Connor McDonald" <connor_mcdonald_at_yahoo.com> wrote in message
> > news:3D4BA164.67D9_at_yahoo.com...
> > > Stjepan Brbot wrote:
> > > >
> > > > What is better:
> > > >
> > > > FOR xy IN curXY LOOP
> > > > ...
> > > > END LOOP;
> > > >
> > > > or
> > > >
> > > > OPEN curXY;
> > > > LOOP
> > > > FETCH curXY INTO xy;
> > > > IF curXY%NOTFOUND THEN
> > > > EXIT;
> > > > END IF;
> > > > ...
> > > > END LOOP;
> > > >
> > > > --
> > > >
> > > > Stjepan Brbot
> > >
> > > The first because
> > >
> > > a) its simpler to read
> > > b) its less code
> > > c) its faster
> > >
> > > If you don't need any cursor attributes through the loop, you can also
> > > code
> > >
> > > for i in ( select ...
> > > from ... ) loop
> > > ...
> > > end loop;
> >
> > I thought that too becuse this is the same situation like with FOR..NEXT
> > vs. WHILE..WEND loops in other programming languages. But I wasn't sure
> > because I had found a lot of code from very expirienced developers using
> > the second way with %NOTFOUND.
> >
> > --
> >
> > Stjepan Brbot

>

> You'll find a lot of people saying that explicity declaring cursors is
> faster than not, ie they will claim that
>

> cursor X is select ...
> open
> fetch
> close
>

> is faster then
>

> select ..
> into variable
> from table
>

> Ask them to prove it...they'll struggle :-)
>

> hth
> connor
> --
> ==============================
> Connor McDonald
>

> http://www.oracledba.co.uk

>
> "Some days you're the pigeon, some days you're the statue..."
Received on Sun Aug 04 2002 - 16:21:44 CDT

Original text of this message

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