SQL-';存在的地方';不带相等检查的子句
有人能解释一下这个语法的作用吗:SQL-';存在的地方';不带相等检查的子句,sql,oracle,oracle11g,oracle10g,Sql,Oracle,Oracle11g,Oracle10g,有人能解释一下这个语法的作用吗: where exists(select * from table(source.sources)) 我不明白这种比较是如何发生的。我习惯的语法是 Select x from y where exists (select 1 from z where z.id = y.id) 在第一个exists语句中,y.id=x.id比较发生在哪里?我可以看一个如何使用第一个语法的例子吗 谢谢看起来源是源表中的嵌套表。下面是一个例子: create type sourc
where exists(select * from table(source.sources))
我不明白这种比较是如何发生的。我习惯的语法是
Select x
from y
where exists (select 1 from z where z.id = y.id)
在第一个exists语句中,y.id=x.id比较发生在哪里?我可以看一个如何使用第一个语法的例子吗
谢谢看起来
源
是源
表中的嵌套表。下面是一个例子:
create type sources_type as table of number
/
create table source (id number, sources sources_type)
nested table sources store as sources_tab;
insert into source (id, sources) values (1, null);
insert into source (id, sources) values (2, sources_type());
insert into source (id, sources) values (3, sources_type(1, 2, 3));
这三行是源的三种可能状态
;null、空表(这不是同一件事)和填充表。如果要选择表不为空的行,则不能检查它是否为null,因为这只是故事的一半
select * from source
where sources is null;
ID SOURCES
---------- ----------------------------------------
1
select * from source
where sources is not null;
ID SOURCES
---------- ----------------------------------------
2 STACKOVERFLOW.SOURCES_TYPE()
3 STACKOVERFLOW.SOURCES_TYPE(1,2,3)
您可能不希望包含id为2的行。因此,您可以查看嵌套的表内容:
select * from source
where not exists (select * from table(sources));
ID SOURCES
---------- ----------------------------------------
1
2 STACKOVERFLOW.SOURCES_TYPE()
select * from source
where exists (select * from table(sources));
ID SOURCES
---------- ----------------------------------------
3 STACKOVERFLOW.SOURCES_TYPE(1,2,3)
所以最终的查询将忽略空的嵌套表以及空值
在第二个示例中,您正在执行一个相关子查询(或者,如果伪代码没有一点损坏,至少我假设您会这样做),在一个表中查找匹配数据,该表不是主查询的一部分,并且(通常)需要相等性测试;在第一个示例中,您正在检查同一个表中是否存在数据,因此没有可比较的内容
您还可以检查嵌套表中的特定值-我不确定这是否澄清或混淆了问题:
select * from source
where exists (select * from table(sources) where column_value = 2);
啊,好的,我知道它在做什么。谢谢你的详细解释。