Oracle 和 MS SQL Server 中 NOT 条件和 NOT() 之间有什么区别

2024-02-23

最近偶然在Sql Server和Oracle中遇到not()。尝试了不同的示例,将 NOT 条件和 not() 与不同的运算符(例如 LIKE、IN 等)进行比较。我在结果集和记录计数方面没有看到任何差异,但想与社区确认这两个操作符是否执行相同的操作或任何警告?

查询示例

select count(*) from Emp where country not in ('ENGLAND UK', 'HAITI', 'IRELAND') 
select count(*) from Emp where not(country  in ('ENGLAND UK', 'HAITI', 'IRELAND')) 

当你有另一种情况时,差异就会存在AND/OR。它反转了AND to OR and OR to AND

select 1 where not(1 = 1 or 1 <> 1 )

将与

select 1 where (1 <> 1 and 1 = 1 )

and

select 1 where not(1 = 1 and 1 <> 1 )

将与

select 1 where (1 <> 1 or 1 = 1 )

and

select 1 where not(1 = 1) or 1 = 1 

不会与相同

select 1 where not(1 = 1 or 1 = 1 )
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Oracle 和 MS SQL Server 中 NOT 条件和 NOT() 之间有什么区别 的相关文章

随机推荐