如下:如果t表中的usercode在a表的customerno中存在相等的记录,则t表中的记录被查询出来。
select t.*
from llclaimuser t
where 1 = 1
and exists (select a.customerno from ldperson a where a.customerno = t.usercode);
exists的写法相对比较复杂,而且exists只能判断是否存在,不能返回具体的条数,不能进行相应的循环处理,也不见的比count(1)效率好多少,所以用你这种写法基本就可以了,简单明了,好维护,如果需要还可以根据查询出的记录数进行循环。
你这样就很好了,其他的方法,如果不用count(1),而是简单的查询字段出来,并且这个sql没有结果返回,就会报错ora-01403的,判断起来更麻烦。
至于你说的exists,实在想不出来怎么判断。
oracle 不存在if exists的判断,现在这个就可以,不用刻意用exists, 你说的exists效率问题是where后面和not in这些比较的吧,不是exists和count的相比。。。