select * from
(select rownum rn from all_objects)
where rn > (select min(fld) from tb)
and rn < (select max(fld) from tb)
and rn not in (select fld from tb);
测试样例及结果:
scott@ORCL> select * from tb;
FLD
----------
1
2
6
9
scott@ORCL> select * from
2 (select rownum rn from all_objects)
3 where rn > (select min(fld) from tb)
4 and rn < (select max(fld) from tb)
5 and rn not in (select fld from tb);
看看这个:
select t5.fld+t6.fcount as fbrknumber
from
(
select t3.fld,t4.fld-t3.fld-1 as fbrkcount
from
(select t1.fld,count(t2.fld)-1 as fcount
from ccc t1 join ccc t2 on t1.fld<=t2.fld
group by t1.fld) t3 left join
(select t1.fld,count(t2.fld)-1 as fcount
from ccc t1 join ccc t2 on t1.fld<=t2.fld
group by t1.fld) t4
on t3.fcount=t4.fcount+1
where t4.fld<>t3.fld+1
) t5,
(select t1.fld,count(t2.fld)-1 as fcount
from ccc t1 join ccc t2 on t1.fld<=t2.fld
group by t1.fld) t6
where t6.fcount<=t5.fbrkcount and t6.fcount>0
order by t5.fld+t6.fcount