现在的位置: 首页 > 综合 > 正文

利用oracle的存储过程和sys_sequence表替代sequence的功能

2019年06月19日 ⁄ 综合 ⁄ 共 347字 ⁄ 字号 评论关闭

利用oracle的存储过程和sys_sequence表替代sequence的功能

该功能能够适用于并发应用下的需求

代码:

create or replace procedure get_sequence(key in varchar2) return number
  ret_val sys_sequence.lastid%type;
begin
  update sys_sequence
     set lastid = lastid + 1
   where code = key;

  if sql%notfound then
    insert into sys_sequence(code, lastid)
    values (key, 1);
  end if;

  select lastid
    into ret_val
   where code = key;

  return ret_val;
end;
/

该代码摘自搜索引擎

抱歉!评论已关闭.