2017-01-30 47 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, '') <> '';