null in sql

Philip Greenspun's Homepage : Philip Greenspun's Homepage Discussion Forums : 6916 : One Thread
Notify me of new responses
I'm wondering how to select a room without a fee.
I've tried setting fee = 0, fee < 0 , fee <= 0 , fee = null,
not fee > 0 in my the where clause but all of them won't work.
However, when i select rooms with fee > 0 in the where clause, it does
eliminate all the rooms without fee and gives me back only those with
a fee.

-- Joyce Ng, October 6, 1999

Answers

Null in sql

To select a null column in sql use: fee is null.

You should remember that NULL is never included in comparisons involving < > <> =, etc. It does not have a value so Oracle will not try to compare it.

-- Jesse Koontz, October 6, 1999


The NVL function can be very useful here. NVL(foo,bar) returns foo if foo is not null, bar if foo is null. So

select * from rooms where NVL(fee,0) = 0;

will get you all rooms where there is no fee or a fee of 0.

-- Robert van der Heide, October 7, 1999


uytyty

-- in sa, June 25, 2007