I’m trying to pass a null value as something else in my db and it seems to work without a Where clause like so
select NVL(column1, '0') column1 from table1
produces this
0 test1
0 test2
1 test3
But when I add the where clause like so
select NVL(column1, '0') column1 from table1 where column1 <=1
it produces this
1 test3
But now if I add the following to the query it works
select NVL(column1, '0') column1
from table1
where NVL(column1, '0') <=1
But it seems like a long way round to get the value to show correctly with a Where clause
Any ideas what i’m doing wrong?
Thanks in advance
You cannot refer to an alias defined in the
SELECTlist from theWHEREclause. So if you apply theNVLfunction in theSELECTlist, you’d need the same function call in theWHEREclause (as you’ve demonstrated) or you would need to apply the function in an inline viewNote that for general sanity, if
COLUMN1is aNUMBER, the second parameter toNVLshould also be aNUMBER. Otherwise, you’re going to do implicit conversions and your comparison operations may end up using string comparison semantics rather than numeric comparison semantics. Since the string ’12’ is less than the string ‘2’, that can lead to unexpected results.