NVL, NVL2 function

The NVL function is a null conversion function. Used to convert a null value (NULL) to an actual value.

The format is as follows:

    NVL(expression1, expression2)

    If expression1 is NULL, NVL returns the value of expression2, otherwise it returns the value of expression1.

Its expression 1 and expression 2 can be numeric, character or date, but the data types of expression 1 and expression 2 must be the same.

E.g:

    Digital: NVL(comm,0)

    Character type: NVL(TO_CHAR(comm),'No Value')

    Date type: NVL(date,'31-DEC-11')

 

 

The NVL2 function is a newly added function of Oracle 9i.

The format is as follows:

    NVL(expression1, expression2, expression3)

    If expression1 is not NULL, the NVL2 function returns the value of expression2.

    If expression1 is NULL, the NVL2 function returns the value of expression3.

Expression 2 and Expression 3 can be of any data type except LONG, and Expression 1 can be of any data type.

 

If the data types of expression 2 and expression 3 are different, the Oracle server converts the data type of expression 3 to the data type of expression 2; at this time, if expression 3 is a null value, the Oracle server does not perform data type conversion.

 

The data type of the return value of the NVL2 function is the same as that of Expression 2. But when the data type of expression 2 is fixed-length character type CHAR, the data type of the return value of NVL2 function is variable-length character type VARCHAR2.

 

Guess you like

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