Original: Decode in Oracle
The Decode function is equivalent to a conditional statement (IF). It compares the input value to the parameter list in the function and returns a corresponding value based on the input value. The parameter list of a function is a number of sequential pairs consisting of several numeric values and their corresponding result values. Of course, the function also has a default return value if it fails to match any one of the actual argument order pairs successfully. Unlike other functions in SQL, the Decode function can also recognize and manipulate null values.
Its specific syntax format is as follows:
DECODE (Input_value,value,result[,value,result ...] [, Default_result]);
which
Input_value the value to be processed. The decode function compares this value to a series of order pairs to determine the final return result
Value is the numeric value of a constituent order pair. If the input value matches successfully, the corresponding result is returned. corresponding to an empty return value, you can use the keyword NULL for the corresponding
result is the resulting value of a constituent sequence couple
The default value returned by the function when the Default_result failed to match any of the sequence pairs successfully
The following example shows how to read an item under the Blood_test_flag column in the User Checkup table Seapark as an argument support value for the Decode function.
SELECT Checkup_type,
DECODE (Blood_test_flag, ' Y ', ' Yes ', ' N ', ' No ', NULL, ' None ', ' Invalid ')
From Checkup;
Decode in Oracle