如何匹配不为空+不为空?

Posted

技术标签:

【中文标题】如何匹配不为空+不为空?【英文标题】:How to match not null + not empty? 【发布时间】:2017-06-15 18:36:38 【问题描述】:

我必须对杂乱无章的数据库进行一些查询。某些列填充有null 或空字符串。我可以这样查询:

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

但是这种情况有捷径吗? (匹配每个“非空”值)类似:

select * from a where b is filled;

【问题讨论】:

不是重复的。另一个问题是null or empty,而这个问题是not null and not empty 【参考方案1】:

select * from a where COALESCE(b, '') &lt;&gt; '';

【讨论】:

【参考方案2】:

只是:

where b <> ''

null &lt;&gt; '' 为 null 时会做你想做的事,并且不会返回该行

【讨论】:

以上是关于如何匹配不为空+不为空?的主要内容,如果未能解决你的问题,请参考以下文章