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 |
|---|---|
IF THEN END IF; | 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. |
IF THEN ELSE END IF; | This combination implements an either/or logic: based on the condition between the IF and THEN keywords, execute the code either between THEN and ELSE or between ELSE and END IF. One of these two sections of executable statements is performed. |
IF THEN ELSIF ELSE END IF; | This last and most complex form of the IF statement selects a condition that is TRUE from a series of mutually exclusive conditions and then executes the set of statements associated with that condition. If you’re writing IF statements like this using any release from Oracle9i Database Release 1 onwards, you should consider using searched CASE statements instead. |
The IF-THEN Combination
The general format of the IF-THEN syntax is as follows:
IFconditionTHEN... sequence of executable statements ...END IF;
The condition is a Boolean variable, constant, or expression that ...
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