New versions: Dev (3.14) | Latest (3.13) | 3.12 | 3.11 | 3.10 | 3.9 | 3.8 | Old versions: 3.7 | 3.6 | 3.5 | 3.4 | 3.3

NVL

Applies to ✅ Open Source Edition   ✅ Express Edition   ✅ Professional Edition   ✅ Enterprise Edition

The NVL() function (or also the ISNULL()) produces the first argument if it is NOT NULL, otherwise the second argument. It is a special case of the COALESCE function, which takes any number of arguments.

SELECT nvl(null, 1);
create.select(nvl(null, 1)).fetch();

The result being

+-----+
| nvl |
+-----+
|   1 |
+-----+

Dialect support

This example using jOOQ:

nvl(null, 1)

Translates to the following dialect specific expressions:

-- ACCESS
iif(NULL IS NULL, 1, NULL)

-- ASE, CUBRID, FIREBIRD, HANA, INFORMIX, REDSHIFT, SQLDATAWAREHOUSE, SQLSERVER, SYBASE, TERADATA, VERTICA
CASE WHEN NULL IS NOT NULL THEN NULL ELSE 1 END

-- AURORA_MYSQL, MARIADB, MEMSQL, MYSQL, SQLITE
ifnull(NULL, 1)

-- AURORA_POSTGRES, COCKROACHDB, DERBY, POSTGRES
COALESCE(NULL, 1)

-- DB2, H2, HSQLDB, INGRES, ORACLE
nvl(NULL, 1)

(These are currently generated with jOOQ 3.14, see #10141)

The jOOQ Logo