Get the next sequence number in the database sql

  ////Get the next serial number in the database

By finding out 1 to the current maximum, the current maximum +2 result set is merged into one, find the two rows of +1 +2 with b is null, and then use rownum=1 to take the first of the two, that is, +1 of 

  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 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326486612&siteId=291194637