A built-in function in the Oracle SQL library. Works similar to an inline IF-THEN-ELSE statement, allowing column values or expressions to be translated:

decode(EXPRESSION_1, VALUE_1, {EXPRESSION_2, VALUE_2, ... , VALUE_n})

EXPRESSION_1 is evaluated for true or false. If EXPRESSION_1 is true, VALUE_1 is returned; otherwise, EXPRESSION_2 is evaluated for true or false. If EXPRESSION_2 is true, VALUE_2 is returned, and so on. If all expressions evaluate to false, then VALUE_n is returned.

This is equivalent to writing in pseudocode:

if (EXPRESSION_1) then
VALUE_1
else
if (EXPRESSION_2) then
VALUE_2
else
VALUE_n
end if
end if

Log in or register to write something here or to contact authors.