1

I have created the table TEST, for use operator <> in database Oralce. When you run the following command, I found it strange not return any records.

why not return any records? In SQL Server and Firebird database the command works.

SQL that is not Working

select * from TEST where Adress <> '';

http://sqlfiddle.com/#!4/7e89f/2

create table TEST(
    ID int not null,
    Name varchar2(100) not null,
    Adress varchar2(100)  
);

alter table TEST add constraint TEST_pk primary key (ID);

insert into TEST values (1, 'Emily', null);
insert into TEST values (2, 'Michael', 'Test');
insert into TEST values (3, 'Daniel', 'Test');
insert into TEST values (4, 'Alexis', 'Test');
Tiedt Tech
  • 719
  • 15
  • 46

1 Answers1

5

Oracle famously treats an empty string as null.

You are doing the same as:

select * from TEST where Adress <> null;

... and the result of anything compared with null is undefined.

You have to use null comparison operators:

select * from TEST where Adress is not null;

Read more about Oracle's handling of nulls.

Community
  • 1
  • 1
Alex Poole
  • 183,384
  • 11
  • 179
  • 318