NVL function in Oracle

NVL is an advanced function that the Oracle database supports. It is used to substitute a value, when a NULL value is encountered. The NVL function is supported in the various versions of the Oracle/PLSQL, including, Oracle 12c, Oracle 11g, Oracle 10g, Oracle 9i and Oracle 8i.


NVL (value, replace_with)

value: It is used to specify the value to be tested for a NULL value.
replace_with: It is used to specify the value to return if value is NULL.


SELECT NVL (attendance, 'Absent')
FROM students;

Here, the NVL function will return ‘Absent’ if the attendance field contains a NULL value. Otherwise, the value of the attendance field will be returned.