Gblog

おもにTips

NULL は、「= NULL」 では抽出できない。

※ 12.2 で動作確認

SQL> select 1 from dual where NULL = NULL;

no rows selected

SQL> select 1 from dual where NULL is NULL;

         1
----------
         1

 

一体、「= NULL」にどんな意味が?

 

ちなみに、空文字「''」でも不思議な挙動。。。

これ、1個目のSQLは、TRUEになると思ってた。。。

SQL> select 1 from dual where ''  = '';

no rows selected

SQL> select 1 from dual where ' ' = ' ';

         1
----------
         1

 

 

ちょっと話が違うけど、IN 句に NULL をいれるとエラーにはならない。

(何も入れないとエラーになる)

SQL> select 1 from dual where NULL IN ();
select 1 from dual where NULL IN ()
                                  *
ERROR at line 1:
ORA-00936: missing expression


SQL> select 1 from dual where NULL IN (NULL);

no rows selected