日期:2014-05-17 浏览次数:20736 次
with t(SERIALNUMBER) as
(
select 33 from dual
union all select 11 from dual
union all select 4 from dual
union all select 5 from dual
union all select 36 from dual
union all select 37 from dual
union all select 2 from dual
)
select r from (select rownum r from dual connect by rownum<51) t1
where not exists(select 1 from t where t.SERIALNUMBER=t1.r)
order by r;
--如果不是範圍從1開始,在where後加限定r的範圍,t1限定到最大就可以了
从来没用过connect by...不过这个函数很好的实现了SQL循环.我贴一个PL/SQL的吧。。。
DECLARE
o_s NUMBER;
BEGIN
FOR i IN 1..50 LOOP
select COUNT(*) INTO o_s from test_20130115 WHERE serialno = i;
IF o_s =0 THEN
dbms_output.put_line(i);
END IF;
END LOOP;
END;