w3resource

SQLite ifnull() function

Description

The ifnull() function returns a copy of its first non-NULL argument, or NULL if both arguments are NULL. Ifnull() must have exactly 2 arguments.
The ifnull() function is equivalent to coalesce() with two arguments.

Syntax:

ifnull(X,Y)

Example: SQLite ifnull() function

The following sqlite statement returns the first expression, i.e. 0, since the first expression is not NULL.

SELECT ifnull(0,2);

Sample Output:

ifnull(0,2)
-----------
0

Example: ifnull() function with non zero 1st argument

The following SQLITE statement returns the first expression, i.e. 1, since the first expression is not NULL.

SELECT IFNULL(1,2);

SELECT ifnull(1,2);

Sample Output:

ifnull(1,2)
-----------
1

Example: ifnull() function NULL

The following SQLITE statement returns the second expression, i.e. 2, since the first expression is NULL.

SELECT IFNULL(NULL,2);

SELECT ifnull(NULL,2);

Sample Output:

ifnull(NULL,2)
--------------
2

Previous: glob()
Next: instr()



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://www.w3resource.com/sqlite/core-functions-ifnull.php