Determine Oracle null == null

前端 未结 11 1859
栀梦
栀梦 2020-11-28 10:07

I wish to search a database table on a nullable column. Sometimes the value I\'m search for is itself NULL. Since Null is equal to nothing, even NULL, saying



        
11条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-28 10:48

    This can also do the job in Oracle.

    WHERE MYCOLUMN || 'X'  = SEARCHVALUE || 'X'
    

    There are some situations where it beats the IS NULL test with the OR.

    I was also surprised that DECODE lets you check NULL against NULL.

    WITH 
    TEST AS
    (
        SELECT NULL A FROM DUAL
    )
    SELECT DECODE (A, NULL, 'NULL IS EQUAL', 'NULL IS NOT EQUAL')
    FROM TEST
    

提交回复
热议问题