decode
(key) function
Applies to: Databricks SQL Databricks Runtime
Returns the value matching the key.
Arguments
expr
: Any expression of a comparable type.keyN
: An expression that matched the type ofexpr
.valueN
: An expression that shares a least common type withdefValue
and the othervalueN
s.defValue
: An optional expression that shares a least common type withvalueN
.
Returns
The result is of the least common type of the valueN
and defValue
.
The function returns the first valueN
for which keyN
matches expr
.
For this function NULL
matches NULL
.
If no keyN
matches expr
, defValue
is returned if it exists.
If no defValue
was specified the result is NULL
.