Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert empty string to null in SQLite

Tags:

sql

sqlite

How to replace/convert empty string with NULL in SELECT query without altering the table or updating the table.

like image 310
mega6382 Avatar asked Apr 09 '14 18:04

mega6382


People also ask

Is null or empty in SQLite?

SQLite IS NOT NULL operator This picture illustrates the partial output: In this tutorial, you have learned how to check if values in a column or an expression is NULL or not by using the IS NULL and IS NOT NULL operators. Was this tutorial helpful ?

How do I change NULL to NA in SQL?

ISNULL Function in SQL Server To use this function, all you need to do is pass the column name in the first parameter and in the second parameter pass the value with which you want to replace the null value. So, now all the null values are replaced with No Name in the Name column.

Does SQLite support Null?

Based on the SQL standard, PRIMARY KEY should always imply NOT NULL . However, SQLite allows NULL values in the PRIMARY KEY column except that a column is INTEGER PRIMARY KEY column or the table is a WITHOUT ROWID table or the column is defined as a NOT NULL column.


1 Answers

The NULLIF function is supported on most major RDBMS's.

SELECT NULLIF(MyColumn, '') FROM MyTable

This will return NULL for any row if MyColumn is equal to the empty string.

like image 184
p.s.w.g Avatar answered Sep 27 '22 15:09

p.s.w.g