select count(1) into v_count from tableName where 条件... and rownum = 1; if v_count <> 0 then -- 符合条件的记录存在 end if;
因为 rownum=1,所以oracle只要扫描到一条符合条件的记录,就不会在继续扫描下去了,当符合同条件的数据量越大时,性能的提高越明显。
select count(1) into v_count from tableName where 条件... and rownum = 1; if v_count <> 0 then -- 符合条件的记录存在 end if;
因为 rownum=1,所以oracle只要扫描到一条符合条件的记录,就不会在继续扫描下去了,当符合同条件的数据量越大时,性能的提高越明显。