Friday, March 03, 2017

Decode SQL

Posted by AnithaKamatchi on Friday, March 03, 2017 in | No comments

Usage : 

Decodes the values of a column with the one specified

How the Decode SQL works????

Consider  table "Participant_List" as shown below









Case :
List all the rows in a table with location specifying the full name

Syntax:
Select decode(<column_name>,
                       value 1,decode_value 1,
                       value 2,decode_value 2,
                       ...
                                   ,default_value)
from <table_name>

Sample Query:

Select participant_id,participant_name,participant_age,
           decode(location,
                        'IN','India',
                        'AU','Australia',
                        'SG','Singapore',
                        'US','United States'
                               ,'Unknown')
from Participant_List

Result:    
      

0 comments:

Post a Comment