Many programming languages have the concept of conditional processing.
Among the most common construct is an if/then structure. Oracle SQL does
allow for conditional processing, but does not use if/then statements
to accomplish it. Instead, the DECODE function and a CASE statement
The DECODE Function
In the demonstration below, the relevant arguments
listed are as follows.
- Argument 1: 1 as the base expression
- Argument 2: 1 as the search expression for the first pair
- Argument 3: 'option 1' as the result expression for the first pair
- Argument 4: 2 as the search expression for the second pair
- Argument 5: 'option 2' as the result expression for the second pair
- Argument 6 (if included): the default value
In some cases, indentation can clarify the logic involved.
This is clearly seen when multiple functions are nested
together or a large numbers of arguments are required.