如何在Oracle sql中过滤空值

时间:2017-03-31 04:24:59

标签: oracle

我想过滤 COMMENTS 属性为空的记录

enter image description here

我试过了

SELECT TABLE_NAME, COMMENTS FROM 
    (SELECT TABLE_NAME, COMMENTS FROM (select * FROM user_tab_comments))
    WHERE COMMENTS != null;

但它没有返回正确的输出。我该怎么办?

1 个答案:

答案 0 :(得分:2)

NULL是一个非价值的州,因此您无法在其上使用普通运算符。请改用IS NULLIS NOT NULL

SELECT TABLE_NAME, COMMENTS 
  FROM (SELECT TABLE_NAME, COMMENTS FROM (select * FROM user_tab_comments))
    WHERE COMMENTS IS NOT NULL;

只是看到你不需要所有这些子查询

SELECT TABLE_NAME, COMMENTS 
  FROM user_tab_comments 
 WHERE COMMENTS IS NOT NULL;