获取数据库中下一个序列号sql

  ////获取数据库中下一个序列号

通过查出1到当前最大,当前最大+2的结果集合并为一个,在用b is null 找到+1 +2 的两行,然后用rownum=1 取这两个中的第一个即+1的 

  select 'E' || trim(to_char(nvl(a, 0), '00000000')) customer_id

  from (select t.a, t1.a b

        from (select rownum a from dual connect by rownum <= (select max(to_number(replace(customer_id, 'E', ''))) + 2 from tb_cus_firm where customer_id like 'E%')) t,

             (select to_number(replace(customer_id, 'E', '')) a from tb_cus_firm where customer_id like 'E%') t1

        where t.a not like '%4%' and t.a = t1.a(+))

 where b is null and rownum = 1 

猜你喜欢

转载自yuhuiblog6338999322098842.iteye.com/blog/2318818
今日推荐