需求:
LWH_TEST表一個SEQ欄位,對應的值(不連續的流水碼)
1,
2,
4,
6,
8
.
.
.
以下SQL可查出缺失的流水號:3,5,7...
select b.SEQ - a.SEQ, b.SEQ, a.SEQ from
( select SEQ , ROWNUM RN from (select SEQ from LWH_TEST order by SEQ) ) a,
( select SEQ , ROWNUM RN from (select SEQ from LWH_TEST order by SEQ) ) b
where a.RN+1 = b.RN
and b.SEQ - a.SEQ > 1
感覺還可以