This function is CASESPECIFIC.
DECODE is a scalar function whose return value data type depends on the data type associated with the result parameter passed into the function.
- If result or default is a numeric type, DECODE determines which argument has the highest precedence and converts the other result or default arguments to that data type and returns that data type.
If that data type is DECIMAL/NUMERIC and the precision and scale of the result or default argument is different, the precision and scale of the return type is set to achieve the maximum precision possible.
For example, if the result / default argument are DECIMAL(6,3), DECIMAL(7,4), and DECIMAL(8,7), the return type needs three digits to the left of the decimal point and seven digits to the right of the decimal point to avoid any reduction in precision. The return data type is set to DECIMAL(10,7).
If the data type is fixed point NUMBER and the precision is less than or equal to 38, the precision and scale of the return type are calculated with the same method used for DECIMAL/NUMERIC. However, if the precision is greater than 38, the return type is changed to NUMBER(*) to avoid loss of accuracy. If the data type is floating point NUMBER, the return type is NUMBER(*).
- If result or default is a character data type, the function returns a VARCHAR in the character set of the first result argument.