SQL > Advanced SQL > DECODE FunctionDECODE 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. The syntax for DECODE is:
SELECT DECODE ( "column_name", "search_value_1", "result_1",
"search_value" is the value to search for, and "result" is the value that is displayed.["search_value_n", "result_n"], {"default_result"} ); For example, assume we have the following Store_Information table, Table Store_Information
SELECT DECODE (Store_Name,
"Area" is the name given to the column with the DECODE statement.'Los Angeles', 'LA', 'San Francisco', 'SF', 'San Diego', 'SD', 'Others') Area, Sales, Txn_Date FROM Store_Information; Result:
|
Saturday, 13 December 2014
SQL DECODE function
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment