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: PLS/SQL: OK to use EXIT in a cursor FOR LOOP ??

Re: PLS/SQL: OK to use EXIT in a cursor FOR LOOP ??

From: Connor McDonald <connor_mcdonald_at_yahoo.com>
Date: Sun, 20 Jun 1999 21:50:03 +0800
Message-ID: <376CF18B.2ADF@yahoo.com>


Kenneth C Stahl wrote:
>
> I'm glad to see that there is someone who agrees with me. It seems to too
> many programmers read about open/fetch/close and get so infatuated that they
> never get around to learning the pure beauty of cursor FOR loops.
>
> As to the whole thing of GOTO, EXIT and raising exceptions. Something that a
> lot of programmers don't fully comprehend is that pl/sql is specifically
> written so that whenever execution passes out of scope for the FOR loop the
> cursor will be automatically closed. Most of the time EXIT is a good choice
> if you simply want to continue processing with the next statement after the
> FOR loop, but there are some rare occasions where a controlled GOTO is
> needed. I was once taught by an Oracle Corporation pl/sql language developer
> that EXIT is merely a synonym for a GOTO to an implicit label immediately
> after the "END LOOP".
>
> Andy Hardy wrote:
>
> >
> > Poor old associates! I suppose that I don't fall for that as I never
> > declare cursor records, as I always use cursor FOR loops (even when I
> > only expect one value to be returned).
> >
> > [snip]
> > >Raising exceptions or using many exit statements is the same as using
> > >Go_To's. In my opinion, that is poor programming practice.
> > >
> >
> > Hm... I tend to agree, I usually use an exception when something invalid
> > has occurred for which there is no sensible way for the procedure to
> > handle. It seems neater than using a set of IF-THEN-ELSE statements.
> >
> > Andy
> > --
> > Andy Hardy. PGP key available on request
> > ===============================================================

Another nice thing is that you don't even need a cursor...

for i in ( select my_data, some_more

           from my_table ) loop  

  blah blah blah
end loop;

works quite nicely...
--



Connor McDonald
"These views mine, no-one elses etc etc" connor_mcdonald_at_yahoo.com

"Some days you're the pigeon, and some days you're the statue." Received on Sun Jun 20 1999 - 08:50:03 CDT

Original text of this message

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