IF-THEN-ELSE IF v13
IF
statements can be nested so that alternative IF
statements can be invoked once it is determined whether or not the conditional of an outer IF
statement is TRUE
or FALSE
.
In the following example the outer IF-THEN-ELSE
statement tests whether or not an employee has a commission. The inner IF-THEN-ELSE
statements then test whether the employee’s total compensation exceeds or is less than the company average.
Note
The logic in this program can be simplified considerably by calculating the employee’s yearly compensation using the NVL
function within the SELECT
command of the cursor declaration, however, the purpose of this example is to demonstrate how IF
statements can be used.
The following is the output from this program.
When you use this form, you are actually nesting an IF
statement inside the ELSE
part of an outer IF
statement. Thus you need one END IF
statement for each nested IF
and one for the parent IF-ELSE
.