What are the usage and differences between Decode and nvl functions in Oracle ?, Decodenvl
Decode
Decode (condition, value 1, translation value 1, value 2, translation value 2 ,..., default Value... else if... else has the same meaning
NVL
Format:NVL (string1, replace_with)
Function: If string1 is NULL, The NVL function returns the value of replace_with; otherwise, the value of string1 is returned. If both parameters are NULL, NULL is returned.
Note: string1 and replace_with must be of the same data type, unless explicitly converted using the TO_CHAR function.
Select nvl (sum (t. dwxhl), 1) from tb_jhde t indicates that if sum (t. dwxhl) = NULL, 1 is returned.
Oracle extends NVL functions and provides NVL2 functions.
NVL2
Nvl2 (E1, E2, E3) function: If E1 is NULL, the function returns E3; otherwise, the function returns E2.
Integration
Decode, NVL, and other functions are often used in combination, such
Select monthid, decode (nvl (sale, 6000), 6000, 'ng ',' OK ') from output
The sign () function returns 0, 1,-1, and,
If a smaller value is set to select monthid, decode (sign (sale-6000),-1, sale, 6000) from output, the smaller value is obtained.