April 6, 2011

Use Decode and Substr

Using Decode and substr together:- 
Decode wil replace the IF-THEN-ELSE
e.g
SELECT full_name,
decode(Current_employee_flag, 'Y', 'EMP',
 'N', 'Not Emp')result
FROM per_all_people_f;
Substr will filter values to the length you specify
Eg
SELECT SUBSTR('Take the first four characters', 1, 4) FIRST_FOUR
FROM dual;

To use both:
SUM(DECODE(Substr(piv.uom, 1, 1), 'M', prrv.result_value, NULL))  amount,

Will result value will grouped for numeric values.

No comments:

Post a Comment

Thanks for your comments submitted.,will review and Post soon! by admin.

COALESCE-SQL

Coalesce- return the null values from the expression. It works similar to a case statement where if expression 1 is false then goes to expr...