Get null == null in SQL

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')

 

Pos terkait

Tinggalkan Balasan

Alamat email Anda tidak akan dipublikasikan. Ruas yang wajib ditandai *

Situs ini menggunakan Akismet untuk mengurangi spam. Pelajari bagaimana data komentar Anda diproses.

0 Komentar

  1. Hello there,

    My name is Aly and I would like to know if you would have any interest to have your website here at codeitworld.com promoted as a resource on our blog alychidesign.com ?

    We are in the midst of updating our broken link resources to include current and up to date resources for our readers. Our resource links are manually approved allowing us to mark a link as a do-follow link as well
    .
    If you may be interested please in being included as a resource on our blog, please let me know.

    Thanks,
    Aly