在Oracle中,any()表示括号内任何一个条件,只要有一个满足即可;而all()表示所有的条件都满足才可以
基础概念
在Oracle中,any()表示括号内任何一个条件,只要有一个满足即可;而all()表示所有的条件都满足才可以。
代码演示
1.all用法
--大于最大值
select * from A where id >= all(select id from A)
--这相当于
select * from A where id >= (select max(id) from A)
--小于最小值
select * from A where id <= all(select id from A)
--这相当于
select * from A where id <= (select min(id) from A)2.any用法
--大于任意一个数即可,大于最小值
select * from A where id >= any(select id from A)
--这相当于
select * from A where id >= (select min(id) from A)
--小于任意一个数即可,小于最大值
select * from A where id <= any(select id from A)
--这相当于
select * from A where id <= (select max(id) from A)Oracle中any和all的区别用法
对于any,all的用法,书中说的比较绕口,难以理解,如果通过举例就会比较清晰.
any的例子:
select * from t_hq_ryxx where gongz > any (select pingjgz from t_hq_bm);
输出的结果是所有大于字段‘pingjgz‘中最小数的值,简单来说就是输出的数全部大于‘pingjgz‘字段中的最小值;
select * from t_hq_ryxx where gongz < all (select pingjgz from t_hq_bm);
输出的结果是所有小于字段‘pingjgz‘中最大数的值,简单来说就是输出的数全部小于‘pingjgz‘字段中的最大值;
即:大于最小值,小于最大值
all的例子:
select * from t_hq_ryxx where gongz > all (select pingjgz from t_hq_bm);
输出的结果是所有大于字段‘pingjgz‘中最大数的值,简单来说就是输出的数全部大于‘pingjgz‘字段中的最大值;
select * from t_hq_ryxx where gongz < all (select pingjgz from t_hq_bm);
输出的结果是所有小于字段‘pingjgz‘中最小数的值,简单来说就是输出的数全部小于‘pingjgz‘字段中的最小值;
即:小于最小值,大于最大值
如果还是不清楚,把下面这句看懂也就够了:
any 就是匹配集合中的任意一个就满足条件了;而 all 要跟所有的都比较,所有都满足以后才为真。
本文标题为:oracle中all、any函数用法与区别说明
基础教程推荐
- Redis中的BigKey问题排查与解决思路详解 2023-07-13
- 关于对MongoDB索引的一些简单理解 2023-07-15
- 还原Sql Server数据库BAK备份文件的3种方式以及常见错误总结 2023-07-29
- Redis五种数据类型详解 2023-07-13
- MySQL实现批量插入测试数据的方式总结 2023-08-12
- SQL数据库十四种案例介绍 2023-08-12
- 在阿里云CentOS 6.8上安装Redis 2023-09-12
- Oracle 数据库启动过程的三阶段、停库四种模式详解 2023-07-23
- centos7中redis安装 2023-09-12
- mysql查询FIND_IN_SET REGEXP实践示例 2023-07-27
