This Oracle tutorial explains how to use the Oracle/PLSQL NVL function with syntax and examples.
The Oracle/PLSQL NVL function lets you substitute a value when a null value is encountered.
The syntax for the NVL function in Oracle/PLSQL is:
The string to test for a null value.
The value returned if string1 is null.
The NVL function returns a substitute value.
The NVL function can be used in the following versions of Oracle/PLSQL:
Let's look at some Oracle NVL function examples and explore how to use the NVL function in Oracle/PLSQL.
For example:
The SQL statement above would return 'n/a' if the supplier_city field contained a null value. Otherwise, it would return the supplier_city value.
Another example using the NVL function in Oracle/PLSQL is:
This SQL statement would return the supplier_name field if the supplier_desc contained a null value. Otherwise, it would return the supplier_desc.
A final example using the NVL function in Oracle/PLSQL is:
This SQL statement would return 0 if the commission field contained a null value. Otherwise, it would return the commission field.
Question: I tried to use the NVL function through VB to access Oracle DB.
To be precise,
I got an oracle error when I use distinct clause with NVL, but when I remove distinct it works fine.
Answer: It is possible to the use the DISTINCT clause with the NVL function. However, the DISTINCT must come before the use of the NVL function. For example:
Hope this helps!
Question: Is it possible to use the NVL function with more than one column with the same function call? To be clear, if i need to apply this NVL function to more than one column like this:
Answer: You will need to make separate NVL function calls for each column. For example: