try:select yourid+1 from tablename where yourid+1 not in(select yourid from tablename );

解决方案 »

  1.   

    set timing on;
    select  zldm+1
    from scott.zlcsb 
    where zldm+1 not in(select zldm from scott.zlcsb ) and zldm <>( select max(zldm) from scott.zlcsb );faint,要是中间缺一大截怎么办?
    我觉得最好不要采用1个SQL解决。用游标吧。
      

  2.   

    我觉的,还是定义一个存储过程比较好。调用db server端函数,减少客户端的工作量。