totn MariaDB Functions

MariaDB: IFNULL Function

This MariaDB tutorial explains how to use the MariaDB IFNULL function with syntax and examples.

Description

The MariaDB IFNULL function allows you to return an alternate value if an expression is NULL.

Syntax

The syntax for the IFNULL function in MariaDB is:

IFNULL( expression, value_if_null )

Parameters or Arguments

expression
The value to test as NULL.
value_if_null
The value to return if expression is NULL.

Note

  • The IFNULL function will return expression, if expression is NOT NULL.
  • The IFNULL function will return value_if_null, if expression is NULL.
  • The IFNULL function is similar to the Nz function in MSAccess.

Applies To

The IFNULL function can be used in the following versions of MariaDB:

  • MariaDB 10

Example

Let's look at some MariaDB IFNULL function examples and explore how to use the IFNULL function in MariaDB.

For example:

SELECT IFNULL('CheckYourMath.com', 'TechOnTheNet.com');
Result: 'CheckYourMath.com'

SELECT IFNULL(NULL, 'TechOnTheNet.com');
Result: 'TechOnTheNet.com'

SELECT IFNULL(DATE('2014-05-19'), '2014-06-10');
Result: '2014-05-19'

SELECT IFNULL(DATE(NULL), '2014-06-10');
Result: '2014-06-10'

SELECT IFNULL(10, 20);
Result: 10

SELECT IFNULL(12/0, 'Dividing by 0 returns NULL');
Result: 'Dividing by 0 returns NULL'