SQLite ifnull() Function

A SQLite ifnull() function is a if-else function that returns the second parameter if the first parameter is NULL, and otherwise returns the first parameter.


Here is the syntax of the SQLite ifnull() function:

ifnull(expr1, expr2)

The SQLite ifnull() function is equivalent to the coalesce(expr1, expr2) function with two parameters.



Required. A value or expression to check if it is NULL.


Required. A value or expression.

Return value

If expr1 is NULL, the ifnull() function returns expr2, otherwise it returns expr1.


This example shows the basic usage of the SQLite ifnull() function:

    ifnull(NULL, 'It is NULL'),
    ifnull('I am not NULL', 'x');
  ifnull(NULL, 'It is NULL') = It is NULL
ifnull('I am not NULL', 'x') = I am not NULL