# NVL2

## Syntax

```sql
NVL2(expr1,expr2,expr3)
```

## Description

The `NVL2` function returns a value based on whether a specified expression is `NULL` or not. If *expr1* is not `NULL`, then `NVL2` returns *expr2*. If *expr1* is `NULL`, then `NVL2` returns *expr3*.

## Examples

```sql
SELECT NVL2(NULL,1,2);
+----------------+
| NVL2(NULL,1,2) |
+----------------+
|              2 |
+----------------+

SELECT NVL2('x',1,2);
+---------------+
| NVL2('x',1,2) |
+---------------+
|             1 |
+---------------+
```

## See Also

* [IFNULL (or NVL)](https://mariadb.com/docs/server/reference/sql-functions/control-flow-functions/ifnull)

<sub>*This page is licensed: CC BY-SA / Gnu FDL*</sub>

{% @marketo/form formId="4316" %}
