Decode function in Oracle pl/sql


DECODE function in Oracle pl/sql





As part of Oracle pl sql training, we will see this DECODE function in Oracle plsql.

a> This DECODE function is available in Oracle plsql.
b> This function is not available in MySQL and SQl server.

DECODE syntax:

SELECT DECODE ("Column_name", "search_value_1","result_1",
                                                               "search_value_2","result_2",
                                                               "search_value_3","result_3"
                                                                              "
                                                                              "
                                                                              --
                                                                              --
                                                               "[search_value_n","result_n]" Result column name from Table_Name.

Sample table

Table Name: Fruit_Details


To display the short name for the Fruits_Name, we are categorize like as below.                                 

 App for Apple                                                                                                                                         Ora  for Orange                                                                                                                                      
 Guv for Guvava                                                                                                                                      
Che for Cherry                                                                                                                                      

SELECT DECODE (Fruits_Name, 'Apple', 'App',
                                                               'Orange', 'Ora', 
                                                                'Guvava', 'Guv', 
                                                                                                   'Cherry', 'Che',                                                                                            'Others') Fruit, Cost, Sale_Date
FROM Fruit_Details;
 

Result:

To achieve the same result as above, we need to use CASE function in SQL server and MySQL.


Track us for more functions in Oracle plsql !!!






Comments