DECODE¶
The DECODE
function takes an expression or column and compares it to a series of search values. It returns a result value that corresponds to the first matching search value, or the default value NULL
if no matches are found.
Syntax¶
The following shows the correct syntax for the DECODE function:
DECODE( <expr> , <search1> , <result1> [ , <search2> , <result2> ... ] [ , <default> ] )
Parameters¶
The following table shows the DECODE parameters:
Parameter |
Description |
---|---|
|
The expression to be evaluated. |
|
A value that |
|
A value that is returnd if |
Return¶
Returns the same type as the argument supplied.
Example¶
CREATE TABLE test1 (european_size int not null);
INSERT INTO test1 values (8),(9),(10),(11);
SELECT european_size,DECODE(european_size,8,40,9,41,10,42,99) from test1;
Output:
+---------------+---------+
|european_size |decode |
+-------------------------+
|8 |40 |
+---------------+---------+
|9 |41 |
+-------------------------+
|10 |42 |
+-------------------------+
|11 |99 |
+-------------------------+