IF-THEN-ELSE IF v16
You can nest IF
statements. This allows you to invoke alternative IF
statements once it's determined whether the conditional of an outer IF
statement is TRUE
or FALSE
.
In this example, the outer IF-THEN-ELSE
statement tests whether 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 by calculating the employee’s yearly compensation using the NVL
function in the SELECT
command of the cursor declaration. However, the purpose of this example is to show the use of IF
statements.
The following is the output from this program:
When you use this form, you're 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
.