Wednesday, March 11, 2009

Oracle NVL Function

NVL function substitutes a value when a null value is encoutered.

SyntaxNVL( string1, replace_with )
string1the string to test for a null value
replace_withthe value returned if string1 is null

Applies to: Oracle 8i, Oracle 9i, Oracle 10g, Oracle 11g

Example #1:

select NVL(supplier_city, 'n/a')
from suppliers;


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.

Example #2:

select supplier_id,
NVL(supplier_desc, supplier_name)
from suppliers;

This SQL statement would return the supplier_name field if the supplier_desc contained a null value. Otherwise, it would return the supplier_desc.

No comments:

Post a Comment