DatabaseOracle

Get null == null in SQL

646
oracle database big
oracle database big

I wish to search a database table on a null table column. Sometimes the value In search for is itself NULL. Since Null is equal to nothing, even NULL.

where MYCOLUMN=SEARCHVALUE

That way if touched will fail.

You can do the IsNull or NVL stuff, but it’s just going to make the engine do more work. You’ll be calling functions to do column conversions

Use what you have

where ((MYCOLUMN=SEARCHVALUE) OR (MYCOLUMN is NULL and SEARCHVALUE is NULL))

I don’t know if it’s simpler, but I’ve occasionally used. Other ways can use

WHERE ISNULL(MyColumn, -1) = ISNULL(SearchValue, -1)

Use NVL to replace null with some dummy value on both sides, as in:

WHERE NVL(MYCOLUMN,0) = NVL(SEARCHVALUE,0)
WHERE NVL(mycolumn,'NULL') = NVL(searchvalue,'NULL')

 

Exit mobile version
Verified by MonsterInsights