background image
<< Inserting New Data Rows in Procedures | Using the IF ... THEN ... ELSE Statement >>
<< Inserting New Data Rows in Procedures | Using the IF ... THEN ... ELSE Statement >>

Controlling Program Flow

Controlling Program Flow
4-22 Oracle Database 2 Day Developer's Guide
Controlling Program Flow
Control structures are the most powerful feature of the PL/SQL extension to SQL.
They let you manipulate data and process it using conditional selection, iterative
control, and sequential statements. Conditional selection is a situation where you may
have different types of data values, and may need to perform different processing
steps. Iterative control is a situation where you need to perform repetitive process
steps on similar data. In general, all the lines of code in your programs run
sequentially; sequential control means that you are choosing to execute an alternate
labeled programming branch (
GOTO
statement).
This section will only cover conditional selection and iterative program flow
structures, such as
IF...THEN...ELSE
,
CASE
,
FOR...LOOP
,
WHILE...LOOP
, and
LOOP...EXIT WHEN
.
Using Conditional Selection Control
Conditional selection structures test an expression that evaluates to a
BOOLEAN
value
TRUE
or
FALSE
. Depending on the value, control structures execute the assigned
sequence of statements. There are two general selection control mechanisms:
IF...THEN...ELSE
and its variations, and the
CASE
statement.
Using IF...THEN...ELSE Selection Control
The
IF...THEN...ELSE
statement runs a sequence of statements conditionally. If the
test condition evaluates to
TRUE
, the program runs statements in the
THEN
clause. If
the condition evaluates to
FALSE
, the program runs the statements in the
ELSE
clause.
You can also use this structure for testing multiple conditions if you include the
ELSIF
See Also:
Oracle Database PL/SQL Language Reference for an overview of
PL/SQL control structures
See Also:
Oracle Database PL/SQL Language Reference for more information
on
IF...THEN...ELSE
selection control
Oracle Database PL/SQL Language Reference for more information
on
CASE...WHEN
selection control