GoingMyWay
GoingMyWay

Reputation: 17478

How to filter null value in Oracle sql

I want to filter the records that COMMENTS attribute is null

enter image description here

I have tried

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

But it didn't return the right output. How can I do it?

Upvotes: 3

Views: 17960

Answers (1)

Jorge Campos
Jorge Campos

Reputation: 23381

NULL is a state not a value, therefore you can't use normal operators on it. Use IS NULL or IS NOT NULL instead.

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

Just saw that you don't need all those subqueries

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

Upvotes: 9

Related Questions