我在一个表中有一个列,它可能包含空值或空值。我如何检查一个列是否为空或空的行中存在的表?

(e.g. null or '' or '  ' or '      ' and ...)

当前回答

你也可以

SELECT * FROM table WHERE column_name LIKE ''

逆存在

SELECT * FROM table WHERE column_name NOT LIKE ''

其他回答

要么

SELECT IF(field1 IS NULL or field1 = '', 'empty', field1) as field1 from tablename

or

SELECT case when field1 IS NULL or field1 = ''
        then 'empty'
        else field1
   end as field1 from tablename

写条件的一种更简短的方法:

WHERE some_col > ''

因为null > "会产生unknown,所以它会过滤掉空字符串和空字符串。

检查空值

$column is null
isnull($column)

检查是否为空

$column != ""

但是,你应该总是为列设置NOT NULL, mysql优化只能处理一个IS NULL级别

你也可以

SELECT * FROM table WHERE column_name LIKE ''

逆存在

SELECT * FROM table WHERE column_name NOT LIKE ''

try

SELECT 0 IS NULL ,  '' IS NULL , NULL IS NULL

-> 0, 0, 1

or

SELECT ISNULL('  ') , ISNULL( NULL )
 -> 0 ,1

参考