Exploring the DECODE Function

The DECODE function is one of the most powerful commands in SQL*Plus—and perhaps the most powerful. The standard language of SQL lacks procedural functions that are contained in languages such as COBOL and C.

The DECODE function is similar to an IF...THEN statement in a procedural programming language. Where flexibility is required for complex reporting needs, DECODE is often able to fill the gap between SQL and the functions of a procedural language. The DECODE function simply says to look in a column for a value and, if found, change the value to another value.

DECODE(column1, value1, output1, value2, output2

Get Sams Teach Yourself SQL in 21 Days, Fourth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.