Purpose
NANVL() determines whether the input value n1 is not a number (NaN) and returns the result.
If
n1isNaN, the function returnsn2.If
n1is notNaN, the function returnsn1.Notice
This function applies only for the
BINARY_FLOATandBINARY_DOUBLEdata types.
Syntax
NANVL(n1,n2)
Parameters
| Parameter | Description |
|---|---|
| n1 | An expression of a numeric data type such as BINARY_FLOAT or BINARY_DOUBLE or any data type that can be implicitly converted to a numeric data type. |
| n2 | An expression of a numeric data type such as BINARY_FLOAT or BINARY_DOUBLE or any data type that can be implicitly converted to a numeric data type. |
Return type
If any of the parameters is of the
BINARY_DOUBLEdata type, the return type isBINARY_DOUBLE.If any of the parameters is of the
BINARY_FLOATdata type, the return type isBINARY_FLOAT.If any of the parameters is null, the function returns
NULL.
Examples
Create the
tbl1table and insert test data into the table. If columncol2is a number, the function 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 of the parameters is null, the function returns
NULL.obclient> SELECT NANVL('',1),NANVL(2,'') FROM DUAL; +-------------+-------------+ | NANVL('',1) | NANVL(2,'') | +-------------+-------------+ | NULL | NULL | +-------------+-------------+ 1 row in set