Chapter 4. Conditional and Sequential Control
This chapter describes two types of PL/SQL control statements: conditional control statements and sequential control statements. Almost every piece of code you write will require conditional control, which is the ability to direct the flow of execution through your program based on a condition. You do this with IF-THEN-ELSE and CASE statements. There are also CASE expressions; while not the same as CASE statements, they can sometimes be used to eliminate the need for an IF or CASE statement altogether. Far less often, you will need to tell PL/SQL to transfer control unconditionally via the GOTO statement, or explicitly to do nothing via the NULL statement.
IF Statements
The IF statement allows you to implement conditional branching logic in your programs. With it, you’ll be able to implement requirements such as:
If the salary is between $10,000 and $20,000, apply a bonus of $1,500.
If the collection contains more than 100 elements, truncate it.
The IF statement comes in three flavors, as shown in the following table.
IF type | Characteristics |
| This is the simplest form of the IF statement. The condition between IF and THEN determines whether the set of statements between THEN and END IF should be executed. If the condition evaluates to FALSE or NULL, the code is not executed. |
| This combination implements an either/or logic: based on the condition between the IF and THEN keywords, execute the code either between ... |
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access