2015-12-15 146 views
0

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

(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 != '') 
+0

length(trim(filename))> 0也许? – bassxzero

+1

如果您的字段索引正确,我认为您的发布解决方案将超越使用诸如“coalesce”之类的函数,否定索引。 – sgeddes

回答

1

我想这是更清晰

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

在某些系统中,这可能表现更差(如@sgeddes注)对索引列。

1

即使当前查询看起来很笨拙,它仍然会执行建议的答案,当您的索引号为file_namefile_last_known_location时。

functionWhere子句使用将使用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 != '')