DECODE Function Examples | VantageCloud Lake - DECODE Function Examples - Teradata Vantage

Teradata® VantageCloud Lake

Deployment
VantageCloud
Edition
Lake
Product
Teradata Vantage
Published
January 2023
Language
English (United States)
Last Update
2024-04-03
dita:mapPath
phg1621910019905.ditamap
dita:ditavalPath
pny1626732985837.ditaval
dita:id
phg1621910019905

Example: Decoding IDs

The following query:

SELECT DECODE(country_id, 1, 'United States',
                          2, 'England',
                          3, 'France',
                          'United States')
    FROM customers; 
returns:
  • 'United States' if the country_id is 1
  • 'England' if the country_id is 2
  • 'France' if the country_id is 3
  • 'United States' if the country_id is not equal to 1, 2, or 3

Example: Decoding IDs Using NULL

The following query

SELECT DECODE(country_id, 1, 'United States', 
                          2, 'England')
    FROM customers; 
returns:
  • 'United States' if the country_id is 1
  • 'England' if country_id is 2
  • NULL if country_id isn't in the range 1 to 2

Example: Decoding IDs When ID is Not Equal to 1, 2 or NULL

The following query:

SELECT DECODE(country_id, 1, 'United States',
                          2, 'England',
                          NULL, 'France')
    FROM customers;
returns:
  • 'United States' if the country_id is 1
  • 'England' if the country_id is 2
  • NULL if the country_id is NULL
  • NULL if the country_id is not equal to 1, 2, or NULL