The Oracle NVL function

The NVL function evaluates a column or an expression this way:

  • If it’s not NULL, it returns the evaluated value.
  • If it’s NULL, it returns the indicated value in the second parameter of NVL.

Syntax

NVL (expression , return_if_null)
The type of the data returned from “expression” must fit the type used in “return_if_null”.

Example

select
name,
surname,
nvl(hobbies,'No hobbies')
from
users;

In this case, we query users table and we want the name, surname and hobbies.
If some user has no hobbies, instead on NULL we are going to see “No hobbies” as a result of the query.

Leave a Reply

Your email address will not be published. Required fields are marked *