oracle查询,什么时候必须用exists?

发布网友 发布时间:2022-04-20 15:48

我来回答

4个回答

热心网友 时间:2023-07-16 21:23

exists可以说是oracle数据库开发中比较常见的用法,用exists可以提高sql的效率,可以取代in。

比如   a,b 关联列为 a.id = b.id,现在要取 a 中的数据,其中id在b中也存在:
select * from a where exists(select 1 from b where a.id = b.id)

现在要取 a 中的数据,其中id在b中   不存在:
select * from a where not exists(select 1 from b where a.id = b.id)

用法详解

热心网友 时间:2023-07-16 21:23

一般用做条件判断,可以防止where的条件语句中,也可以放在case when的条件语句中。exits一般就是判断后面所跟的子查询是否有记录,如果有记录存在exists就为true,否则为false。一般格式:

exists (select ....)

例如:

select 'true' as val from al
where exists (select 1 from al);

热心网友 时间:2023-07-16 21:24

比如 a,b 关联列为 a.id = b.id,现在要取 a 中的数据,其中id在b中也存在:

select * from a where exists(select 1 from b where a.id = b.id)

或者:
现在要取 a 中的数据,其中id在b中 不存在:

select * from a where not exists(select 1 from b where a.id = b.id)

热心网友 时间:2023-07-16 21:24

if exists (select * from table whre a=1)--------(如果这个select 语句能查询出资料就执 begin end 中的语句)

begin

end

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com