Oracle sql decode processing

In this section we will discuss about Oracle sql decode processing which is very important aspect in Oracle sql statement
Oracle sql decode is the method in Oracle database to  transform data values for one value to another which is better to understand.Decode transform data values at retrieval timeThe code block for Oracle sql Decode is belowdecode(expression or column name, match, result [,match, result]…[,default] )

Here are the meaning for terms in above code
a) expression or column  is the value to compare
b) match is the value that is compared against expression
c) result is the value returned, if expression is equal to match
d) default is optional. If no matches are found, the decode will return default. If default is omitted, then the decode statement will return NULL (no matches found).


decode (
Phase Code,

Here is the algorithm to better understand it

1) Oracle retrive  the column value of Phase code
2) if Phase code = ‘P’  then Pending
3) if Phase code = ‘C’  then Completed
4) if Phase code = ‘T’  then Terminated
5) if Phase code = ‘S’  then Standby
6) If Phase code is neither of the above ,the decode returns Unknown
7) If default is not present it will give null

Note that Oracle decode starts by specifying the column name or expression , followed by set of matched-pairs of transformation values. At the end of the decode statement we find a default value. The default value tells decode what to display if a column values is not in the paired list.