Introduction to the Decode () function:
Main role: Translation of query results into other values (that is, in other forms of expression, the following examples);
How to use:
Select decode (ColumnName, value 1, translation value 1, value 2, translation value 2,... Value n, translation value n, default value)
From Talbename
Where ...
Where ColumnName is the column defined in the table to be selected,
• Explanation of Meaning:
Decode (condition, value 1, translation value 1, value 2, translation value 2,... The value n, the translation value n, the default value) is understood as follows:
if (condition = = value 1)
Then
return (translation value 1)
elsif (Condition = = value 2)
Then
Return (translation value 2)
......
elsif (Condition = = value N)
Then
return (translated value n)
Else
return (default value)
End If
Note: The default value can be either the column name you want to select, or the other values you want to define, such as other;
To illustrate:
Now defines a table named output, where two column definitions are Monthid (VAR) and sale (number type), translated to d,=2000 when translated to c,=3000 when sale value =1000 translation to a , if other values are translated as other;
SQL is as follows:
Select Monthid, decode (sale,1000, ' D ', +, ' C ', +, ' B ', 4000, ' A ', ' other ') sale from output
Excerpt from: https://www.cnblogs.com/freespider/archive/2010/08/09/1795977.html
"PL/SQL query" query results translated into other values _decode