SQLite Ifnull() Function

Here we will learn ifnull() function in SQLite and how to use SQLite ifnull() function to return first non-null expression value with examples.

SQLite Ifnull() Function

In SQLite Ifnull() function will accept two parameters same as coalesce function and return the first non-NULL expression value.

 

In Ifnull() function if first parameter is not NULL then it will return the first parameter value in case if the first parameter is NULL then alternatively it will return the second parameter value.

 

If both parameters or expressions in Ifnull() function are NULL then it will return a NULL value.

Syntax of SQLite Ifnull() Function

Following is the syntax of SQLite Ifnull() function to return the first non-NULL parameter value or NULL value in case if both the parameters are NULL.

 

ifnull( param1, param2 )

If you observe above SQLite Ifnull function syntax we defined a few parameters those are

 

param1, param2 – Two parameter values which we will send to Ifnull() function to return first parameter value in case if its non-NULL value otherwise it will return the second parameter value.

 

Now we will see how to use SQLite Ifnull() function to return first parameter or second parameter value with examples.

SQLite Ifnull() Function with Examples

Following are the simple examples of using the SQLite Ifnull() function.

 

sqlite>SELECT ifnull('tutlane', 'welcome');

 

ifnull('tutlane','welcome')

-----------------------------

tutlane

 

sqlite>SELECT ifnull(NULL, 'tutlane');

 

ifnull(NULL,'tutlane')

-----------------

tutlane

 

sqlite>SELECT ifnull(NULL, NULL);

 

ifnull(NULL,NULL)

---------------

NULL

This is how we can use SQLite Ifnull() function to get first parameter value or NULL value based on our requirements. 

Topics Covered