The difference between Decode and NVL and NVL2

Decode

decode (condition, value 1, translation value 1, value 2, translation value 2, ..., default value)    This function has the same meaning as If...else if...else in the program

NVL

Format: NVL( string1, replace_with)

Function: If string1 is NULL, the NVL function returns the value of replace_with, otherwise it returns the value of string1, if both parameters are NULL, it returns NULL.

Note: string1 and replace_with must be of the same data type, unless the TO_CHAR function is explicitly used for type conversion.

select nvl(sum(t.dwxhl),1) from tb_jhde t means return 1 if sum(t.dwxhl) = NULL

Oracle extends the functionality of NVL functions and provides NVL2 functions

NVL2

The function of nvl2 (E1, E2, E3) is: if E1 is NULL, the function returns E3, otherwise returns E2

It is often used in combination with functions such as Decode and NVL, for example

select monthid,decode(nvl(sale,6000),6000,'NG','OK') from output

expand knowledge

The sign() function returns 0, 1, -1 depending on whether a value is 0, positive or negative, respectively.

If you take the smaller value, it is select

monthid,decode(sign(sale-6000),-1,sale,6000) from output, that is, to achieve the purpose of taking a smaller value.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326226762&siteId=291194637