DECODE is a function in Oracle and is used to provide if-then-else type of logic to SQL. It is not available in MySQL or SQL Server.
It is only used for the MySql server and in the Oracle server for the case like manipulation that we perform in the SQL server.
Decode is like the conditional statement that is used for the manipulation of the data stored in the tables.
SELECT DECODE ( "column_name", "search_value_1", "result_1",
["search_value_n", "result_n"],
{"default_result"} );
So it is mainly used for the database except the Sql Server database it could be used to create a column alias for the display values when we want.
SELECT DECODE(EmpFirstName,
'Himanshu', 'H',
'Mayank', 'M',
'Ravi', 'R',
'Others') [EmpMiddleName], [EmpLastname], [EmpAddress]
FROM [EmployeeDetails]
If we want it to manipulate something based on some condition for the table data it will do this also for the database programmer.
SELECT DECODE(StudentMarks,
>60, 'C',
>70, 'B',
>80, 'A',
'Below Standard') [StudentName], [StudentClass]
FROM [StudentDetails]
0 Comment(s)