了解一下NULLs怎样影响IN和EXISTS

 了解一下NULLs怎样影响IN和EXISTS 作者： Builder.com 2004-10-25 10:57:38

[@more@]

 了解一下NULLs怎样影响IN和EXISTS 作者： Builder.com 2004-10-25 10:57:38

select 'true' from dual where 1 = null;

select 'true' from dual where 1 != null;

select 'true' from dual where 1 is null;

select 'true' from dual where null is null;

select 'true' from dual where null in (null);

select 'true' from dual where (null,null) in ((null,null));

select 'true' from dual where (1,null) in ((1,null));

select 'true' from dual where null = ANY (null);

select 'true' from dual where (null,null) = ANY ((null,null));

select 'true' from dual where (1,null) = ANY ((1,null));

select 'true' from dual where exists (select null from dual);

select 'true' from dual where exists (select 0 from dual where null is null);

selectename from emp where empno in (select mgr from emp);

selectename from emp e where exists (select 0 from emp where mgr = e.empno);

selectename from emp where empno not in (select mgr from emp);

selectename from emp e where not exists (select 0 from emp where mgr =e.empno);

NOT　IN子句实际上与用＝比较每一个值相同，如果任何一个测试为FALSE　或NULL的话，它就会失败。例如:

select 'true' from dual where 1 not in (null,2);

select 'true' from dual where 1 != null and 1 != 2;

select 'true' from dual where (1,2) not in ((2,3),(2,null));

select 'true' from dual where (1,null) not in ((1,2),(2,3));

select 'true' from dual where 1 not in (2,3);

select 'true' from dual where 1 != 2 and 1 != 3;

selectename from emp where empno not in (select mgr from emp where mgr is not null);

selectename from emp where empno not in (select nvl(mgr,0) from emp);

• 博文量
3
• 访问量
4734