我在一个表中有一个列,它可能包含空值或空值。我如何检查一个列是否为空或空的行中存在的表?
(e.g. null or '' or ' ' or ' ' and ...)
我在一个表中有一个列,它可能包含空值或空值。我如何检查一个列是否为空或空的行中存在的表?
(e.g. null or '' or ' ' or ' ' and ...)
当前回答
select * from table where length(RTRIM(LTRIM(column_name))) > 0
其他回答
如果你想在做ORDER BY时最后呈现NULL值,试试这个:
SELECT * FROM my_table WHERE NULLIF(some_col, '') IS NULL;
要么
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
try
SELECT 0 IS NULL , '' IS NULL , NULL IS NULL
-> 0, 0, 1
or
SELECT ISNULL(' ') , ISNULL( NULL )
-> 0 ,1
参考
SELECT column_name FROM table_name WHERE column_name IN (NULL, '')
你也可以
SELECT * FROM table WHERE column_name LIKE ''
逆存在
SELECT * FROM table WHERE column_name NOT LIKE ''