رفتار NULL در شرط های اوراکل
رفتار NULL را در عملگرهای مختلف را در Oracle مشاهده می کنیم:
مثال اول: همانطور که مشاهده می کنید NULL = NULL در اوراکل هیچ رکوردی بر نمیگردد.
select '1=0' as test from dual where 1 = 0
Union
select '1=1' as test from dual where 1 = 1
Union
select '1=NULL' as test from dual where 1 = NULL
Union
select 'NULL=NULL' as test from dual where NULL = NULL
Union
select '1=1' as test from dual where 1 = 1
Union
select '1=NULL' as test from dual where 1 = NULL
Union
select 'NULL=NULL' as test from dual where NULL = NULL
Result:
1=1
Result:
1=1
مثال دوم: همانطور که مشاهده می کنید NULL != NULL در اوراکل هیچ رکوردی بر نمیگردد.
select '1!=1' as test from dual where 1!= 1
Union
select '1!=NULL' as test from dual where 1 != NULL
Union
select 'NULL=NULL' as test from dual where NULL != NULL
Union
select '1!=NULL' as test from dual where 1 != NULL
Union
select 'NULL=NULL' as test from dual where NULL != NULL
Result:
---
---
مثال سوم: همانطور که مشاهده می کنید هر موقع از IS در اوراکل برای NULL استفاده کنیم رکورد بر میگرداند.
select '1 IS NULL' as test from dual where 1 IS NULL
Union
select 'NULL IS NULL' as test from dual where NULL IS NULL
Union
select 'NULL IS NOT NULL' as test from dual where NULL IS NOT NULL
Union
select '1 IS NOT NULL' as test from dual where 1 IS NOT NULL
Union
select 'NULL IS NULL' as test from dual where NULL IS NULL
Union
select 'NULL IS NOT NULL' as test from dual where NULL IS NOT NULL
Union
select '1 IS NOT NULL' as test from dual where 1 IS NOT NULL
Result:
1 IS NOT NULL
NULL IS NULL
1 IS NOT NULL
NULL IS NULL
مثال چهارم:
select 'True and NULL' as test from dual where ((1=1) and (NULL=NULL))
Union
select 'False and NULL' as test from dual where ((1=2) and (NULL=NULL))
Union
select 'True or NULL' as test from dual where ((1=1) or (NULL=NULL))
Union
select 'False and NULL' as test from dual where ((1=2) or (NULL=NULL))
Union
select 'False and NULL' as test from dual where ((1=2) and (NULL=NULL))
Union
select 'True or NULL' as test from dual where ((1=1) or (NULL=NULL))
Union
select 'False and NULL' as test from dual where ((1=2) or (NULL=NULL))
Result:
True or NULL
True or NULL