Oracle CASE WHEN: Usage & Examples
In Oracle, the CASE WHEN statement is used in queries to select different results based on conditions. The syntax is as follows:
SELECT
CASE
WHEN condition1 THEN result1
WHEN condition2 THEN result2
...
ELSE default_result
END AS alias
FROM table_name;
In this case, condition1, condition2, etc. represent the conditional expressions, while result1, result2, etc. represent the results returned when the conditional expressions are true. The default_result is the default result returned when none of the conditional expressions are true, and alias represents the alias of the result column.
The CASE WHEN statement can be used in the SELECT query’s result set, WHERE clause, ORDER BY clause, etc., to display or sort different results based on specific conditions.