Purpose
This function determines whether the input value parameter n1 is NaN (not a number) and returns the result.
If
n1isNaN, it returns the value of parametern2.If
n1is notNaN, it returns the value of parametern1.Notice
This function applies only to the
BINARY_FLOATorBINARY_DOUBLEdata types.
Syntax
NANVL(n1,n2)
Parameters
Parameter |
Description |
|---|---|
| n1 | A numeric data type (BINARY_FLOAT or BINARY_DOUBLE) or an expression that can be implicitly converted to a numeric data type. |
| n2 | A numeric data type (BINARY_FLOAT or BINARY_DOUBLE) or an expression that can be implicitly converted to a numeric data type. |
Return type
If any parameter is of the
BINARY_DOUBLEdata type, the return type isBINARY_DOUBLE.If all parameters are of the
BINARY_FLOATdata type, the return type isBINARY_FLOAT.If any parameter is
NULL, the return value isNULL.
Examples
Create a table named
tbl1and insert test data. If the value in columncol2is numeric, it returns the original value; otherwise, it returns0.obclient> CREATE TABLE tbl1 (col1 NUMBER(10,2), col2 BINARY_DOUBLE, col3 BINARY_FLOAT); Query OK, 0 rows affected obclient> INSERT INTO tbl1 VALUES(1,1,1),(2,'NaN',2),(3,3,'NaN'); Query OK, 3 rows affected Records: 3 Duplicates: 0 Warnings: 0 obclient> SELECT * FROM tbl1; +------+----------+----------+ | COL1 | COL2 | COL3 | +------+----------+----------+ | 1 | 1.0E+000 | 1.0E+000 | | 2 | Nan | 2.0E+000 | | 3 | 3.0E+000 | Nan | +------+----------+----------+ 3 rows in set obclient> SELECT col2,NANVL(col2,0) FROM tbl1; +----------+---------------+ | COL2 | NANVL(COL2,0) | +----------+---------------+ | 1.0E+000 | 1.0E+000 | | Nan | 0 | | 3.0E+000 | 3.0E+000 | +----------+---------------+ 3 rows in setIf any parameter is
NULL, the return value isNULL.obclient> SELECT NANVL('',1),NANVL(2,'') FROM DUAL; +-------------+-------------+ | NANVL('',1) | NANVL(2,'') | +-------------+-------------+ | NULL | NULL | +-------------+-------------+ 1 row in set
