NVL and IFNULL

Applies to: ✅ Data 360 SQL ✅ Tableau Hyper API

IFNULL and NVL both return a replacement expression when the input expression is NULL.

Syntax 

1nvl(<expr>, <replacement>)
2ifnull(<expr>, <replacement>)

Arguments 

Required 

  • <expr>: Expression to check for NULL.
  • <replacement>: Expression returned when <expr> is NULL.

Returns 

Returns <expr> when it isn’t NULL; otherwise, returns <replacement>. Argument types must be compatible.

Considerations 

  • Requires exactly two arguments.
  • IFNULL is an alias of NVL.
  • Equivalent to COALESCE with these two arguments.

Examples 

Replace NULL 

Return the replacement when the first expression is NULL.

1SELECT nvl(NULL, 99) AS result;

Returns 99.

IFNULL returns the same result:

1SELECT ifnull(NULL, 99) AS result;

Returns 99.

Keep a non-NULL value 

Return the first expression when it isn’t NULL.

1SELECT nvl(42, 0) AS result;

Returns 42.

Related Documentation