Introducing Radical.sh

Forget Code launches a powerful code generator for building API's

CASE STATEMENT in Oracle

CASE
expressions in oracle is similar to IF ... THEN ... ELSE logic in SQL statements.
Evaluated in Top to bottom approach, If a condition is true, then corresponding THEN clause is executed and execution jumps to the END CASE clause.

syntax:
CASE [ expression ]
   WHEN condition_1 THEN result_1
   WHEN condition_2 THEN result_2
   ...
   WHEN condition_n THEN result_n
   ELSE result
END


Example:

SELECT emp_name, emp_no, dept_no
  (CASE dept_no
     WHEN 10 THEN 'ACCOUNTS'
     WHEN 20 THEN 'HR'
     WHEN 30 THEN 'OPERATIONS'
     WHEN 40 THEN 'SALES'
     ELSE 'UNKNOWN'
   END) DEPARTMENT
FROM EMPLOYEE
ORDER BY emp_name;