2017-01-30 49 views
5

我必须对凌乱的数据库进行一些查询。一些列填充了null或空字符串。我可以做这样的查询:如何匹配不为空+不为空?

select * from a where b is not null and b <> ''; 

但是有没有这种情况下的快捷方式? (符合每一个 “不空” 的值)是这样的:

select * from a where b is filled; 
+0

不重复。另一个问题是'空或空',而这个问题'不为空而不是空' –

回答

7

刚:

where b <> '' 

会做你想要什么为null <> ''为null,并且该行不会返回

1

select * from a where COALESCE(b, '') <> '';