本教程操作环境:windows10系统、oracle 11g版、dell g3电脑。
oracle中and和or的区别是什么1.and表示交
2.or表示并
3.and的优先级比or高
(firstname='thomas' or firstname='william') and lastname='carter' 会得到 lastname 必须为 carter ,firstname 为 thomas 或者 william的人 thomas carter william carterfirstname='thomas' or firstname='william' and lastname='carter' 可以得到 william carter 或者 firstname 为ithomas lastname 不一定是 carter的人 比如: thomas carter william carter thomas king
就是 or 和and 的先后顺序的问题, and 的优先级比 or的高 ,a or b and c 先计算 b and c 的结果 再去计算 a 的。
and优先级大于or。
加括号则优先执行or,后执行and;不加括号,会先执行and,再执行or,所以查询结果不同。举例:
数据库存在数据:
thomas carter
william carter
thomas king
执行:
select * from persons where (firstname='thomas' or firstname='william')and lastname='carter'
结果为:
thomas carter
william carter
执行:
select * from persons where firstname='thomas' or firstname='william'and lastname='carter'
结果为:
thomas carter
william carter
thomas king
推荐教程:《oracle视频教程》
以上就是oracle中and和or的区别是什么的详细内容。
