PL/SQL Decode

The Decode function compares one expression to one or more other expressions and, when the search term is found, returns the match result expression.

Decode syntax

DECODE (expression , search, result [, search , result]... [, default])

Decode example

STUDENT_IDFIRST_NAMELAST_NAMECITY
1DanielSCOTTNew York
2AnthonySIMMONSChicago
3SophiaTHOMPSONLos Angeles
SELECT s.STUDENT_ID, s.FIRST_NAME, s.LAST_NAME, s.CITY,
DECODE(s.CITY, 'Los Angeles', 'L.A.', 'New York', 'N.Y.', s.CITY) AS SHORT_CITY
FROM students s;
STUDENT_IDFIRST_NAMELAST_NAMECITYSHORT_CITY
1DanielSCOTTNew YorkN.Y.
2AnthonySIMMONSChicagoChicago
3SophiaTHOMPSONLos AngelesL.A.