在oracle数据库中,有一张表A,其中主键为ID,由00001开始排序,现在排序到06000.
我想知道由00001至06000间存在的断号。
求一连号查断号sql语句,谢谢各位了!

解决方案 »

  1.   

    select id ,nextId,nextId-id --断了几
    from (select id ,lead(id) over(order by id) as nextId)
    where nextId-id>1
      

  2.   


    select a.al,b.id
      from (
    select lpad(level,4,'0') al
      from dual
      connect by level <= 10) a,tab_1 b
      where a.al = b.id(+)
        and b.id is null
        order by a.al;
      

  3.   


    ---用这个...
     select id from tab start with to_number(id) = 1 connect by to_number(id)<=6000
      

  4.   

    不错
    如果要查其中断了哪些号
    select id
    from(
      select rownum id from dual connect by rownum<=(select to_number(max(id)) from TABLE1))t
    where not exists(
      select 1 from TABLE1 where id=to_char(t.id,'fm00000'))