繁体   English   中英

检查列是否不为空或为空

[英]Checking if a column is not null or empty

有没有更好的方法来执行以下操作以检查列是否不为空/空?

(v.file_name is not null and v.file_name != '' 
 and v.file_last_known_location is not null and v.file_last_known_location != '')

我认为这更清楚

COALESCE(v.file_name,'') != '' AND COALESCE(v.file_last_known_location,'') != ''

在某些系统上,这对索引列的性能可能更糟(如@sgeddes所述)。

我要说的是,即使当前查询看起来很笨拙,当在file_namefile_last_known_location上建立索引时,它也会执行建议的答案。

Where子句中使用function会限制优化器使用Index 所以最好使用原始查询

(v.file_name is not null and v.file_name != '' 
 and v.file_last_known_location is not null and v.file_last_known_location != '')

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM