NVL Function

The NVL expression returns different results, depending on whether its first argument evaluates to NULL.

NVL Function

NVL(expr1, expr2)
Element Description Restrictions Syntax
expr1 expr2 Expressions that return values of a compatible data type Cannot be a host variable or a BYTE or TEXT object Expression

NVL evaluates expression1. If expression1 is not NULL, then NVL returns the value of expression1. If expression1 is NULL, NVL returns the value of expression2. The expressions expression1 and expression2 can be of any data type, as long as they can be cast to a common compatible data type.

Suppose that the addr column of the employees table has NULL values in some rows, and the user wants to be able to print the label Address unknown for these rows. The user enters the following SELECT statement to display the label Address unknown when the addr column has a NULL value:
SELECT fname, NVL (addr, 'Address unknown') AS address 
   FROM employees;