in

Oracle Select Case Example

In Oracle, the CASE statement is used to perform the if..else condition in the SQL query. Below is an Oracle Select Case example:

CASE Statement Syntax

CASE [ expression ]

   WHEN condition_1 THEN result_1
   WHEN condition_2 THEN result_2
   ...
   WHEN condition_n THEN result_n

   ELSE result

END

Oracle Select Case Example

The following Oracle SQL query calculates the new salary depending on the job.

SELECT
  ename,
  job,
  SAL,
  CASE job
    WHEN 'MANAGER'
    THEN SAL + (SAL * 30/100)
    WHEN 'CLERK'
    THEN SAL + (SAL * 20/100)
    ELSE SAL + (SAL * 10/100)
  END new_salary
FROM
  EMP
ORDER BY
  ENAME;

Output

NAMEJOBSALNEW_SALARY
ADAMSCLERK11001320
ALLENSALESMAN16001760
BLAKEMANAGER28503705
CLARKMANAGER24503185
FORDANALYST30003300

Written by Rony Dsouza

Rony is an Oracle programmer, having more than 15 years of experience. He likes to write on SQL, PL/SQL, and Oracle Apex topics. Also, expertise in Python, PHP, MySQL, JavaScript, etc.

Leave a Reply

Your email address will not be published. Required fields are marked *