In Oracle : Oracle SQL Case

Oracle Applications EBS 11i, R12      Oracle Database      Data Warehouse & BI      Oracle Middleware      PL/SQL      Linux ...

Oracle SQL & PL/SQL

Oracle SQL Oracle PL/SQL

The last articles in the site (HOT)

The most visited articles in the site

In-Oracle.com  -> Oracle SQL & PLSQL

-> Oracle SQL Case

 

 Oracle SQL Case

 

CASE Expression in an Oracle SELECT statement

The CASE expression is a more complex version of the DECODE function.

 

This case of CASE use is another way to "rewrite" a DECODE function:

 

SELECT ename, empno,
              (  CASE deptno
                 WHEN 10  THEN 'Accounting'
                 WHEN 20  THEN 'Research'
                    ELSE 'Unknown'
                END ) department
FROM emp
ORDER BY ename;

 

is another way of writing:

 


SELECT ename, empno,
               DECODE (deptno,
                                       10, 'Accounting',
                                       20, 'Research',
                                             'Unknown' ) department
FROM emp
ORDER BY ename;

 

Note: In this case the execution plan doesn't change.

 

Using the CASE function, multiple conditions can be combined into one:

 

 

SELECT ename, empno,
               (CASE
                   WHEN sal < 2500 THEN 'Low'
                   WHEN sal >= 2500 THEN 'High'
                END) salary
FROM emp
ORDER BY ename;

 

Oracle SQL Case

 

 

 

In-Oracle.com  -> Oracle SQL & PLSQL

-> Oracle SQL Case

Oracle Applications EBS 11i, R12      Oracle Database      Data Warehouse & BI      Oracle Middleware      PL/SQL      Linux ...

 

     Copyright (c) 2011-2015  www.in-oracle.com  |  Disclaimer: The views expressed on this web site are my own and do not reflect the views of Oracle Corporation. You may use the information from this site only at your risk.