The DECODE function
You can use the DECODE function to
convert an expression of one value to another value. The DECODE function
has the following form:
DECODE(test, a, a_value, b, b_value, ..., n, n_value, exp_m )
The DECODE function returns a_value when a equals test, and returns b_value when b equals test, and, in general, returns n_value when n equals test.
If several expressions match test, DECODE returns n_value for the first expression found. If no expression matches test, DECODE returns exp_m; if no expression matches test and there is no exp_m, DECODE returns NULL.
Restriction: The DECODE function
does not support arguments of type TEXT or BYTE.
Suppose
an employee table exists that includes emp_id and evaluation columns.
Suppose also that execution of the following query on the employee table
returns the rows that the result shows.
In some cases, you might want to convert a set of values.
For example, suppose you want to convert the descriptive values of
the evaluation column in the preceding example to corresponding
numeric values. The following query shows how you might use the DECODE function
to convert values from the evaluation column to numeric values
for each row in the employee table.
You can specify any data type for the arguments of the DECODE function
provided that the arguments meet the following requirements:
- The arguments test, a,b, ..., n all have the same data type or evaluate to a common compatible data type.
- The arguments a_value, b_value, ..., n_value all have the same data type or evaluate to a common compatible data type.