Built-In Functions: Decode

Description: A type of replacement function within the SELECT statement.

SELECT id,
  DECODE(customer_id, 'AOL', 'America Online') Company,
  order_date
FROM test2
WHERE ROWNUM < 21
/
 
 
SELECT program_id,
       DECODE(customer_id,
              'AOL', 'America Online',
              'TW', 'Time Warner',
              'ORCL', 'Oracle Corporation',
              'NetApp', Network Appliances',
       order_date
FROM test2
WHERE ROWNUM < 21
/
 
 
decode with default
 
SELECT program_id,
       DECODE(customer_id,
              'AOL', 'America Online',
              'TW', 'TIME Warner',
              'ORCL', 'Oracle Corporation',
              'NetApp', Network Appliances',
              'OTHER'
       order_date
FROM test2
WHERE ROWNUM < 21
/

Enjoyed this post? Share it!

 

Leave a comment

Your email address will not be published.