# 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" %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://mariadb.com/docs/server/reference/sql-functions/control-flow-functions/nvl2.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
