CASE Statements and Expressions
The CASE statement allows you to select one sequence of statements to execute out of many possible sequences. CASE statements have been part of the SQL standard since 1992, although Oracle SQL didn’t support CASE until the release of Oracle8i Database, and PL/SQL didn’t support CASE until Oracle9i Database Release 1. From this release onward, the following types of CASE statements are supported:
- Simple CASE statement
Associates each of one or more sequences of PL/SQL statements with a value. Chooses which sequence of statements to execute based on an expression that returns one of those values.
- Searched CASE statement
Chooses which of one or more sequences of PL/SQL statements to execute by evaluating a list of Boolean conditions. The sequence of statements associated with the first condition that evaluates to TRUE is executed.
In addition to CASE statements, PL/SQL also supports CASE expressions . A CASE expression is very similar in form to a CASE statement and allows you to choose which of one or more expressions to evaluate. The result of a CASE expression is a single value, whereas the result of a CASE statement is the execution of a sequence of PL/SQL statements.
Simple CASE statement
A simple CASE statement allows you to choose which of several sequences of PL/SQL statements to execute based on the results of a single expression. Here is an example of a simple CASE statement that uses the employee type as a basis for selecting the proper bonus ...