some any oracle,oracle中any,some,all用法

oracle 中 any , some , all 用法

平时工作中,很少用 any 、 some 、 all ,今天突然看到这种用法,感觉很不错,工作中应该能用到;

用 some,any 和 all 对子查询中返回的多行结果进行处理。

下面我们来简单介一下这几个关键词的含义。

Some 在此表示满足其中一个的意义,是用 or 串起来的比较从句。

Any 也表示满足其中一个的意义,也是用 or 串起来的比较从句,区别是 any 一般用在非 “=” 的比较关系中,这也很好理解,英文中的否定句中使用 any 肯定句中使用 some ,这一点是一样的。

All 则表示满足其其中所有的查询结果的含义,使用 and 串起来的比较从句。

Any

带【 any 】的嵌套查询和【 some 】的嵌套查询功能是一样的。早期的 SQL 仅仅允许使用【 any 】,后来的版本为了和英语的【 any 】相区分,引入了【 some 】,同时还保留了【 any 】关键词。

any:

select emp.empno,emp.ename,emp.job,emp.sal from scott.emp where sal >any(select sal from scott.emp where job='MANAGER');

带 any 的查询过程等价于两步的执行过程。

( 1 )执行 “select sal from scott.emp where job='MANAGER'”

select emp.empno,emp.ename,emp.job,emp.sal from scott.emp where sal >2975 or sal>2850 or sal>2450;

some

some:

select emp.empno,emp.ename,emp.job,emp.sal from scott.emp where sal =some(select sal from scott.emp where job='MANAGER');

带 some 的嵌套查询与 any 的步骤相同。

( 1 )子查询 , 执行 “select sal from scott.emp where job='MANAGER'”, 其结果如图 4.22 所示。

( 2 )父查询执行下列语句。

―――――――――――――――――――――――――――――――――――――

select emp.empno,emp.ename,emp.job,emp.sal from scott.emp where sal =2975 or sal=2850 or sal=2450;

all

all 是查询还可以是子查询

如:

select name from edit

其中 name 前省略了 all.

name 前可以加 ALL|DISTINCT

all 是所有记录 .

distinct 是不重复的。

select emp.empno,emp.ename,emp.job,emp.sal from scott.emp where sal >all(select sal from scott.emp where job= 'MANAGER' );

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值