Database Reference
In-Depth Information
Figure 14.1
SQL Inline CASE
Statement Syntax.
shown in Figure 14.1. See Chapter 24 for the PL/SQL version of the
CASE statement.
Chapter 9 contained a DECODE example based on the states in which
artists live, duplicated here for convenience:
SELECT STATE_PROVINCE
, DECODE(STATE_PROVINCE,'CA','Surfer',
'NH','Snow bunny',
'OR', 'Tree hugger',
'FL', 'Retired',
'Whatever!')
FROM ARTIST;
Now let's convert the Chapter 9 DECODE example to use an inline
CASE statement rather than the DECODE function. The following exam-
ple contains a simple CASE statement format, which will produce the same
result as the DECODE example in Chapter 9, Figure 9.12:
SELECT STATE_PROVINCE
, CASE STATE_PROVINCE
WHEN 'CA' THEN 'Surfer'
WHEN 'NH' THEN 'Snow bunny'
WHEN 'OR' THEN 'Tree hugger'
WHEN 'FL' THEN 'Retired'
ELSE 'Whatever!' END
FROM ARTIST;
 
Search WWH ::




Custom Search