image

CHAPTER16DECODE and CASE: IF, THEN, and ELSE in SQL

The DECODE function is without doubt one of the most powerful in Oracle’s SQL. It is one of several extensions Oracle added to the standard SQL language. This chapter explores a number of ways that DECODE can be used, including the generation of “crosstab” reports. You can also use the CASE function and the COALESCE function to execute complex logical tests within your SQL statements.

DECODE and CASE are often used to pivot data—that is, to turn rows of data into columns of a report. In this chapter, you will see how to use DECODE, CASE, and the PIVOT operator (introduced in Oracle 11g) to generate ...

Get Oracle Database 12c The Complete Reference 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.