7 maggio 2013

Oracle Decode function: syntax and example


The decode function has the capabilities of an IF-THEN-ELSE statement.
Typically is used to trasform data values for one value to another.

It's possible apply it on Oracle 11g, 10g and 9i.

SYNTAX:
  decode( ExpressionToTest , True1 , Result1 [, Truen , Resultn]... [, default] )

Note: If default is omitted, then Oracle returns null.

EXAMPLE:
1)
select
decode (
gender,
‘M’,’Male’,
‘F’,’Female’,
‘UNKNOWN’
) as Gender
from 
employees;

Nessun commento: