select min(id) from (select id,rownum from t1 where id<>rownum)

解决方案 »

  1.   

    select id from (select id from tab where trim(replace(id,'1234567890',' ')) is not null) where rownum<2
      

  2.   

    SQL> select id,rownum from t;ID     ROWNUM
    -- ----------
    1           1
    2           2
    4           3
    6           4
    7           5SQL> select id,rownum from t where id<>rownum;ID     ROWNUM
    -- ----------
    2           1
    4           2
    6           3
    7           4SQL> select min(id) from
      2  (select id,rownum from t where id<>rownum);MI
    --
    2SQL> select id from (select id from t where trim(replace(id,'1234567890',' '))
      2   is not null) where rownum<2;ID
    --
    1这两个方法似乎有点问题。
    楼主要找到第一个没有出现的数字,这个数字不是在表中的,需要对查出来的id进行处理。
      

  3.   

    SQL> select max(id)+1 from t
      2  where id=rownum; MAX(ID)+1
    ----------
             3