Skip to content

NVL

Return the value of the first expression that is not null in a list of two expressions. If both expressions are null, NVL returns null. ISNULL and NVL are aliases for the same conditional expression. See also COALESCE, which is similar to NVL and ISNULL but allows more than two expressions in the list.

NVL( expression1, expression2 )
ISNULL( expression1, expression2 )

For example:

premdb=# select isnull(null,1) from sys.const;
 isnull 
--------
     1
(1 row)

premdb=# select nvl(null,null) from sys.const;
  nvl 
--------
 [NULL]
(1 row)

In this example, if the city column value is null, return No City:

premdb=# select teamid, nvl(city,'No City') from team order by teamid desc;
 teamid |      nvl      
--------+---------------
    50 | No City
    49 | No City
    48 | No City
    47 | Wolverhampton
    46 | London
    45 | Wigan
    44 | London
...

Make sure the list of expressions consists of compatible data types. For example, you cannot reference a SMALLINT and a VARCHAR in an NVL expression.

Parent topic:Conditional Expressions