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
Expression1andExpression2must 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
Expression1is character data, thenExpression2is converted to the same data type ofExpression1and returns the result in aVARCHAR2in the character set ofExpression1. -
If
Expression1is 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
Expression1isNULL, theNVLfunction returnsExpression2. IfExpression1isNOT NULL, theNVLfunction returnsExpression1. -
The
NVLfunction can be used in theWHEREorHAVINGclause ofSELECT,UPDATE, orDELETEstatements and in theSELECTlist of aSELECTstatement.
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.