NVL
The NVL
function replaces a null value with a second value.
SQL syntax
NVL(Expression1, Expression2)
Parameters
NVL
has the parameters:
Parameter | Description |
---|---|
|
The expression whose values are to be tested for |
|
The alternate value to use if the value of |
Description
-
The data types of
Expression1
andExpression2
must be compatible. If the data types are different, the data types are implicitly converted, if possible. If they cannot be implicitly converted, an error is returned.The following describes how the implicit conversion of data types is performed:
-
If
Expression1
is character data, thenExpression2
is converted to the same data type ofExpression1
and returns the result in aVARCHAR2
in the character set ofExpression1
. -
If
Expression1
is numeric data, then TimesTen determines which expression has the highest numeric precedence and implicitly converts the other argument to that data type, which is also the data type that is returned.
-
-
If
Expression1
isNULL
, theNVL
function returnsExpression2
. IfExpression1
isNOT NULL
, theNVL
function returnsExpression1
. -
The
NVL
function can be used in theWHERE
orHAVING
clause ofSELECT
,UPDATE
, orDELETE
statements and in theSELECT
list of aSELECT
statement.
Examples
This example checks for null values of commission_pct
and replaces them with 'Not Applicable'
for employees whose last names start with "B".
Command> SELECT last_name, NVL(TO_CHAR(commission_pct), 'Not Applicable') FROM employees WHERE last_name LIKE 'B%' ORDER BY last_name; < Baer, Not Applicable > < Baida, Not Applicable > < Banda, .1 > < Bates, .15 > < Bell, Not Applicable > < Bernstein, .25 > < Bissot, Not Applicable > < Bloom, .2 > < Bull, Not Applicable > 9 rows found.