Oracle Database 10g SQL (Osborne ORACLE Press Series)
You may use the IF, THEN, ELSE, ELSIF, and END IF keywords in PL/SQL for performing conditional logic. The following syntax illustrates the use of conditional logic:
IF condition1 THEN statements1 ELSIF condition2 THEN statements2 ELSE statements3 END IF;
where
-
condition1 and condition2 are Boolean expressions that evaluate to true or false.
-
statements1 , statements2 , and statements3 are PL/SQL statements.
This conditional logic flows as follows :
-
If condition1 is true, then statements1 is executed.
-
If condition1 is false but condition2 is true, then statements2 is executed.
-
If neither condition1 nor condition2 are true, then statements3 is executed.
You can also embed IF statements within another IF statement, as shown in the following example:
IF count > 0 THEN message := 'count is positive'; IF area > 0 THEN message := 'count and area are positive'; END IF ELSIF count = 0 THEN message := 'count is zero'; ELSE message := 'count is negative'; END IF;