The oracle function library provides many useful functions, such as nvl, sign, and round. The decode function is used in many cases. This function is used as follows: decode (expression, condition 1, result 1, condition 2, result 2 ,...) there are several conditions and results in the middle depending on the individual. For example, decode (sign (100-20), 1,100,-100) means that when (-20) is greater than zero, the result is 20, and when
The oracle function library provides many useful functions, such as nvl, sign, and round. The decode function is used in many cases. The function is used as follows:
Decode (expression, condition 1, result 1, condition 2, result 2,...) contains several conditions and results depending on the individual, as shown in
Decode (sign (100-20), 1,100,-100) means that when (100-20) is greater than zero, the result is 20, and when (-20) is less than zero, the result is 100. The sign is only a function for determining the symbol.
If we want to adjust the salaries of employees in an enterprise and increase the salaries by 3000 for employees of less than 10% yuan and 3000 for employees of more than 5% yuan, then our general practice is to judge the wages, if the value is greater than 3000, 5% is added, and if the value is lower than 3000, 10% is added. However, with this decode function, you can simply use the following statement:
Select decode (sign (salary-3000), 1, salary * 1.1,-1, salary * 1.05) from employee
Haha, this is simple and clear.