Oracle 动态主键序列创建

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

drop sequence order;
declare
v_sql varchar2(1000);
v_num number(20):=1;
begin
v_sql:='create sequence order_sq';
select max(order_sq.id)+1 into v_num from order;
if v_num is null then v_num :=1;
end if;
v_sql:=v_sql||' minvalue 1 maxvalue 9999999999999999999999999999 start with '||v_num ||' increment by 1 cache 20';
execute immediate v_sql;
end;