©SQL :: Manager
HomeProgram InformationTechnical detailsFree downloadDonate for a cup of coffee
myway SQL Manager for MySQL and MariaDB, Download on Uptodown
SQL functionMariaDB

MariaDB NVL2 SQL Function - If NULL selection - Oracle

NVL2Syntax:NVL2(Expression, Value1, Value2)
Return value:Depending on the data types used
Function type:NULL function
Function Description

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
nvl2('ok', 'Value2', 'Value2')
varchar(6) BINARY
nvl2(nullif('ok', 'notok'), 'value1', 'Value2')
varchar(6) BINARY
nvl2(nullif('ok', 'ok'), 'value1', 'Value2')
varchar(6) BINARY
The examples were created with the MyWAY SQL manager: Download

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 about COALESCE Function

IFNULLIFNULL(Expression, Value)
More about IFNULL Function

More about ISNULL Function

NULLIFNULLIF(Expression 1, Expression 2)
More about NULLIF Function

NVLNVL(Expression, Value)
More about NVL Function

Numeric functionsString functionsRegular ExpressionsDate and Time functions
Comparison functionsEncryption & CompressionConversion functionsNULL functions
Aggregate functionsWindow functionsJSON functionsGeometric functions
Sequence functionsInformation functionsDynamic ColumnsMiscellaneous functions
More information about the NVL2 SQL function: mariadb.com
Updated: 2023-09-24ImprintContactTerms & conditionsPrivacy & CookiesUpdatesSitemapFacebookLinkedinTwitterStatistics©2020-2023 Heino Cunze-Fischer