今天PM通知我将所有的SEQ增减10W,研究了一下,才明白怎么回事(本人比较笨^_^)。
第一步:将SEQ的步长增加10W (把冰箱门打开)
第二步:执行nextval (把大象转进去)
第三步:将SEQ的步长修改到本来步长 (把冰箱门带上)
select 'alter sequence ' || t1.sequence_name || ' increment by 100000 nocache;' from user_sequences t1
union all
select 'select ' || t2.sequence_name || '.nextval from dual;' from user_sequences t2
union all
select 'alter sequence ' || t3.sequence_name || ' increment by 2 nocache;' from user_sequences t3;
简简单单三步走,搞定所有问题,嘿嘿……
------------------------------------------------------------------------------
本人写这篇东东只是为了学习提高,根据2L和4L的朋友的提议,本人将原有操作修改了一下,这样就可以做到动态了,而不必理会SEQ的原先步长。
declare
v_sql varchar2(500);
begin
for addCurrValue in (select s.sequence_name seqName,
s.increment_by seqIncrement
from user_sequences s) loop
/* 将SEQ的步长修改修改为100000 */
v_sql := 'alter sequence ' || addCurrValue.seqName || ' increment by 100000 nocache;';
execute immediate v_sql;
/* 获取SEQ的下一个值 */
v_sql := 'select ' || addCurrValue.seqName || '.nextval from dual;';
execute immediate v_sql;
/* 将SEQ的步长修改回原先的步长 */
v_sql := 'alter sequence ' || addCurrValue.seqName || ' increment by ' || addCurrValue.seqIncrement || ' nocache;';
execute immediate v_sql;
commit;
end loop;
end;
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/25086534/viewspace-682068/ ,如需转载,请注明出处,否则将追究法律责任。