SQLite Ifnull() Function

  Total Views : 422
  Comments : 0
  Keywords : SQLite ifnull function to return first non-null expression, SQLite return null or non-null value using ifnull() function with examples

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 first non-NULL expression value.

 

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

 

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

Syntax of SQLite Ifnull() Function

Following is the syntax of SQLite Ifnull() function to return 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 few paramaters 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 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 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. 

 Comments (0)

Be the first to give your valuable feedback

Leave a comment

  • Default Tutlane User