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

From: Kenneth C Stahl <kstahl_at_lucent.com>
Date: Fri, 18 Jun 1999 08:22:34 -0400
Message-ID: <376A3A0A.C3FAE7A0_at_lucent.com>


[Quoted] 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
> ===============================================================
Received on Fri Jun 18 1999 - 14:22:34 CEST

Original text of this message