Welcome to Oracle PL SQL Performance Tuning and Optimization. At Oracle PL SQL Performance Tuning and Optimization talk about Using DECODE or CASE Function

Monday, August 27

Using DECODE or CASE Function

Using DECODE or CASE Function : 

Oracle 8i introduced the CASE function to be more compliant with ANSI SQL standards. The CASE function can replace the DECODE function in most situations. The CASE function lets you put IF-THEN-ELSE processing in your SQL statements. To use a CASE function instead of the DECODE function in the first example, the SQL statements would have to be rewritten as follows:

SELECT loc, CASE loc
WHEN 'NEW YORK' THEN 'EASTERN'
  WHEN 'BOSTON' THEN 'EASTERN'
  WHEN 'DALLAS' THEN 'CENTRAL'
WHEN 'LOS ANGELES' THEN 'WESTERN'
ELSE 'UNKNOWN'
END  AS region
  FROM dept;

The CASE function can be more readable than the DECODE function, although their role is the same when used this way. Additionally, other RDBMS systems do not support Oracle's DECODE function. Using CASE can save the application developer time when creating applications that will be used on multiple RDBMS platforms.

0 comments:

Post a Comment

Copyright © 2013 Oracle PL SQL Performance Tuning and Optimization | Oracle PL SQL Performance Tuning and Optimization