Re: PL/SQL best practices ? How to go to end of loop (i.e. next record)

From: Toon Koppelaars <toon_at_rulegen.com>
Date: Thu, 10 Feb 2011 07:06:59 +0100
Message-ID: <AANLkTinD8ucRgY7Mgcdu_FSrYaAiW+J=jzMcSkeJjZkz_at_mail.gmail.com>



Avoid goto at all cost.

http://www.u.arizona.edu/~rubinson/copyright_violations/Go_To_Considered_Harmful.html

On Wed, Feb 9, 2011 at 10:45 PM, Michael Moore <michaeljmoore_at_gmail.com>wrote:

> I can think of many ways to do this but is there a definitive best
> practice?
> I'm sure there must be articles on this somewhere, so links as well as
> comments are appreciated.
>
> BEGIN
> for cur1 in (SELECT bla bla bla)
> LOOP
>
> If something_I_dont_like then skip to next record in cur1;
>
> Lots and lots of code goes here.
>
> END LOOP;
> END;
>
> Some options:
> 1) You could set up a label and use a goto.
> 2) You could set up an inner block and use RAISE to break out:
>
> 3) You could do something like :
>
> BEGIN
> for cur1 in (SELECT bla bla bla)
> LOOP
> <<process_this_record>>
> FOR c2 IN (SELECT * FROM DUAL) -- creates an exitable one-time
> loop
> LOOP
>
> If something then
> exit process_this_record;
>
> Lots and lots of code goes here.
>
> END LOOP process_this_record;
> END LOOP;
> END;
>
> 4) You could just nest IF statements like:
>
> BEGIN
> for cur1 in (SELECT bla bla bla)
> LOOP
> IF keep_processing_this_transaction THEN
> BEGIN
> Lots and lots of code goes here.
> END IF;
> END LOOP;
> END;
>
> So, what is the best way?
>
> Regards,
> Mike
>

-- 
Toon Koppelaars
RuleGen BV
Toon.Koppelaars_at_RuleGen.com
www.RuleGen.com
TheHelsinkiDeclaration.blogspot.com

(co)Author: "Applied Mathematics for Database Professionals"
www.RuleGen.com/pls/apex/f?p=14265:13

--
http://www.freelists.org/webpage/oracle-l
Received on Thu Feb 10 2011 - 00:06:59 CST

Original text of this message