Oracle   Home  

 

Oracle Database 9i, 10g, 11g

Oracle Data Warehouse & BI

Oracle Applications EBS 11i, R12

 Oracle Middleware

SQL & PL/SQL

UNIX/ Linux

   Home  >  Oracle SQL & PL/SQL  >  CASE Expression in an Oracle SELECT statement

 

Oracle SQL & PL/SQL

CASE Expression in an Oracle SELECT statement

 

Note: The article ( named CASE Expression in an Oracle SELECT statement ) was taken from www.in-oracle.com.

 

 

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;

 

 

 

Note: The article ( named CASE Expression in an Oracle SELECT statement ) was taken from www.in-oracle.com.

 

 

 

Oracle Database 9i, 10g, 11g

Oracle Data Warehouse & BI Oracle Applications EBS 11i, R12  Oracle Middleware

SQL & PL/SQL

UNIX/ Linux

   Home  >  Oracle SQL & PL/SQL  >  CASE Expression in an Oracle SELECT statement

 

 

Different Romanian Links/ Linkuri romanesti diferite

  1. Invata limba engleza (Learn English language if you are Romanian)

  Doresti un proiect de arhitectura ieftin (pentru zonele Buzau, Bucuresti sau Prahova) ?

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. Copyright (c) 2009-2011 Paul Catalin Tomoiu. All rights reserved.