MariaDB NVL2 SQL Function - If NULL selection - Oracle |
|
| NVL2 | Syntax: | NVL2(Expression, Value1, Value2) | Return value: | Depending on the data types used | Function type: | NULL function | |
| | The NVL2() function returns "Value2" if the value of "Expression" is NULL.
If "Expression" is not NULL, NVL2() returns the "Value1".
The feature was introduced starting with MariaDB Version 10.3 for Oracle compatibility.
In MySQL 8.0 this feature is not present. | SQL Examples for the NVL2 function |
|
SELECT nvl2(null, 'Value1', 'Value2');
SELECT nvl2('ok', 'Value2', 'Value2');
SELECT nvl2(nullif('ok', 'notok'), 'value1', 'Value2');
SELECT nvl2(nullif('ok', 'ok'), 'value1', 'Value2');
|
|
nvl2(null, 'Value1', 'Value2') |
varchar(6) BINARY |
Value2 |
|
|
nvl2('ok', 'Value2', 'Value2') |
varchar(6) BINARY |
Value2 |
|
|
nvl2(nullif('ok', 'notok'), 'value1', 'Value2') |
varchar(6) BINARY |
value1 |
|
|
nvl2(nullif('ok', 'ok'), 'value1', 'Value2') |
varchar(6) BINARY |
Value2 |
|
|
| The examples were created with the MyWAY SQL manager: | How to use the NVL2() function in MariaDB databases | The NVL2() function in MariaDB can handle NULL values by having the function provide different alternative values, depending on whether a table column or expression evaluates to NULL or not, providing flexibility in handling NULL values and allowing SQL queries to be returned adjust based on the nullness of the expression. The first parameter is the expression to evaluate, followed by the value to return if the expression is not NULL and the value to return if the expression is NULL. The function was introduced in MariaDB for Oracle compatibility. | | Further MySQL und MariaDB SQL NULL functions | |
| | More information about the NVL2 SQL function: |
|
|
|
|