Build logic using the IF-THEN-ELSE and ELSIF statements.
IF-THEN-ELSE statements using PL/SQL
You can build logic within your PL/SQL block to execute a sequence of statements based on a particular condition.
The selection structure tests a condition then executes one sequence of statements instead of another, depending on the condition.
There are three forms of IF statements.
IF-THEN Structure
This sequence of statements executes only if the conditi evaluates to TRUE.
If the condition evaluates to FALSE or NULL, the IF statement does nothing. In either case, the control passes to the next statement.
IF-THEN-ELSE structure
The sequence of statements in the ELSE clause is executed only if the condition evaluates to FALSE or NULL. The ELSE clause ensures that a sequence of statements is executed. The ELSE clause can include IF statements (nested IF). This construct allows selection of action from several mutually exclusive alternatives. An IF statement can have any number of ELSIF clauses, but the final ELSE clause is optional. Conditions are evaluated one by one from top to bottom as described in the MouseOver below.
Notice that the ELSEIF word is spelled as ELSIF, with a missing E, within PL/SQL.
You can have any number of IF clauses nested within an IF clause. However, you can have only one ELSE clause for every IF clause. In the next lesson, you will learn to build a PL/SQL block with the IF clause through an evaluative simulation.