Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Re: PL/SQL Beginner Question ...

Re: PL/SQL Beginner Question ...

From: Mark D Powell <Mark.Powell_at_eds.com>
Date: 8 Apr 2007 17:40:26 -0700
Message-ID: <1176079226.294938.54880@n76g2000hsh.googlegroups.com>


On Apr 5, 2:37 pm, DA Morgan <damor..._at_psoug.org> wrote:
> cdecarlo wrote:
> > Hello,
>
> > I'm just reviewing some pl/sql code that I've been given and I was
> > wondering if someone could educate me regarding how a pl/sql IF
> > statement is evaluated, does it short circuit the evaluation once one
> > truth is determined or does it evaluate the entire expression? Does it
> > evaluate left to right or right to left?
>
> > Also, are these two blocks contextually the same? Which uses better
> > style?
>
> > Firstly consider there are functions titled functionX where X is a
> > number from 1 to 4, each function will return a boolean value.
>
> > IF NOT function1
> > THEN IF NOT function2
> > THEN IF NOT function3
> > THEN IF NOT function4
> > THEN
> > statement;
> > END IF;
> > END IF:
> > END IF;
> > END IF;
> > END IF;
>
> > vs.
>
> > IF function1 THEN
> > statement;
> > ELSEIF function2 THEN
> > statement;
> > ELSEIF function3 THEN
> > statement;
> > ELSEIF function4 THEN
> > statement;
> > ELSE
> > statement;
> > END IF;
>
> > Thanks,
>
> > cdecarlo
>
> At the first expression that returns true it follows that branch.
> Nothing thereafter is evaluated.
> --
> Daniel A. Morgan
> University of Washington
> damor..._at_x.washington.edu
> (replace x with u to respond)
> Puget Sound Oracle Users Groupwww.psoug.org- Hide quoted text -
>
> - Show quoted text -

To add to what Daniel said if you use compound conditions: AND, OR then in the case of an OR Oracle stops as soon as one condition is true and will not test the other expressions. With an AND obviously all expressions must be evaluated.

HTH -- Mark D Powell -- Received on Sun Apr 08 2007 - 19:40:26 CDT

Original text of this message

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