SQL NVL Function: Syntax, Usage & Examples

In SQL, the NVL function is used to check if an expression is NULL, and if it is NULL, it returns another specified value. The basic syntax is as follows:

NVL(expression, replacement_value)

The ‘expression’ is the expression to be checked, and ‘replacement_value’ is the value to be returned when ‘expression’ is NULL.

For example, to check if the salary field in a table is NULL and return 0 if it is, you can use the following SQL statement:

SELECT NVL(salary, 0) AS new_salary
FROM employees;

This will return a new salary column, returning 0 if the original salary column is NULL.

bannerAds