---
title: ifnull function
description: Learn the syntax of the ifnull function of the SQL language in Databricks SQL and Databricks Runtime.
canonical_url: https://docs.databricks.com/aws/en/sql/language-manual/functions/ifnull
---

# `ifnull` function

**Applies to:** ![check marked yes](https://docs.databricks.com/aws/en/images/icons/check.png) Databricks SQL ![check marked yes](https://docs.databricks.com/aws/en/images/icons/check.png) Databricks Runtime

Returns `expr2` if `expr1` is `NULL`, or `expr1` otherwise. This function is a synonym for [`coalesce(expr1, expr2)`](https://docs.databricks.com/aws/en/sql/language-manual/functions/coalesce.md) with two arguments.

## Syntax

```
ifnull(expr1, expr2)
```

## Arguments

* `expr1`: An expression of any type.
* `expr2`: An expression sharing a [least common type](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-datatype-rules.md#least-common-type-resolution) with `expr1`.

## Returns

The result type is the [least common type](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-datatype-rules.md#least-common-type-resolution) of `expr1` and `expr2`.

## Examples

```sql
> SELECT ifnull(NULL, array('2'));
 [2]
```

## Related functions

* [`coalesce` function](https://docs.databricks.com/aws/en/sql/language-manual/functions/coalesce.md)
* [`if` function](https://docs.databricks.com/aws/en/sql/language-manual/functions/if.md)
* [`nvl` function](https://docs.databricks.com/aws/en/sql/language-manual/functions/nvl.md)
* [`nvl2` function](https://docs.databricks.com/aws/en/sql/language-manual/functions/nvl2.md)
