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_ID FIRST_NAME LAST_NAME CITY
1 Daniel SCOTT New York
2 Anthony SIMMONS Chicago
3 Sophia THOMPSON Los 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_ID FIRST_NAME LAST_NAME CITY SHORT_CITY
1 Daniel SCOTT New York N.Y.
2 Anthony SIMMONS Chicago Chicago
3 Sophia THOMPSON Los Angeles L.A.