103. DECODE - llighter/database GitHub Wiki
DECODE Database SQL Reference
Syntax
Purpose
DECODE
comparesexpr
to eachsearch
value one by one.- If
expr is equal to a
search, then Oracle Database returns the corresponding
result`. - If no match is found, then Oracle returns
default
. Ifdefault
is omitted, then Oracle returnsnull
.
- The arguments can be any of the numeric types (
NUMBER
,BINARY_FLOAT
, orBINARY_DOUBLE
) or character types. - The
search
,result
, anddefault
values can be derived from expressions. - Oracle Database uses short-circuit evaluation. :
νλ μ°ΎμΌλ©΄ λ μ΄μ λΉκ΅νμ§ μλλ€.
- In a
DECODE
function, Oracle considers two nulls to be equivalent. - The maximum number of components in the
DECODE
function, includingexpr
,searches
,results
, anddefault
, is 255.
Examples
SELECT product_id,
DECODE (warehouse_id, 1, 'Southlake',
2, 'San Francisco',
3, 'New Jersey',
4, 'Seattle',
'Non domestic')
"Location of inventory" FROM inventories
WHERE product_id < 1775;