Firebird Documentation Index → Firebird 2.1 Language Ref. Update → Internal functions → DECODE() |
Find a more recent version at Firebird 5.0 Language Reference: DECODE()
Available in: DSQL, PSQL
Added in: 2.1
Description: DECODE is a shortcut for the so-called “simple CASE”
construct, in which a given expression is compared to a number of other expressions
until a match is found. The result is determined by the value listed after the matching
expression. If no match is found, the default result is returned, if present. Otherwise,
NULL
is returned.
Result type: Varies
Syntax:
DECODE (<test-expr>
,<expr>
,result
[,<expr>
,result
...] [,defaultresult
] )The equivalent CASE construct:
CASE<test-expr>
WHEN<expr>
THENresult
[WHEN<expr>
THENresult
...] [ELSEdefaultresult
] ENDCaution
Matching is done with the “
=
” operator, so if<test-expr>
isNULL
, it won't match any of the<expr>
s, not even those that areNULL
.
Example:
select name, age, decode( upper(sex), 'M', 'Male', 'F', 'Female', 'Unknown' ), religion from people
See also: CASE, Simple CASE
Firebird Documentation Index → Firebird 2.1 Language Ref. Update → Internal functions → DECODE() |