长期以来,我一直在使用EXISTS
子句来确定给定条件下给定表中是否至少存在一条记录。 - 例如,如果我想看看是否由姓氏=“史密斯”雇员在“雇员”表存在,我用下面的查询Oracle EXISTS子句Vs ROWNUM = 1
select 1
into v_exists_flag
from dual
where exists (select 1
from employee
where lastname = 'smith'
)
这比使用次数肯定更有效的是(*)条款。
select count(*)
into v_count
from employee
where lastname = 'smith'
如果v_count> 0,则....
不过,最近有人指出,使用ROWNUM = 1比使用如下图所示
select 1
into v_count
from employee
where lastname = 'smith'
and rownum = 1
难道这就是EXISTS子句更好的性能正确?有人可以证实这一点。
在此先感谢
谢谢你们俩(斯蒂芬和普热米斯瓦夫)! – user2836468
嗨Przemyslaw - 我刚刚读过Adam Musch的文章。按照他的职位 - 如果列被编入索引,则无显着差异。 – user2836468
对不起 - 我误打误打了。 – user2836468