码迷,mamicode.com
首页 > 数据库 > 详细

oracle 序列重置

时间:2015-06-24 19:05:18      阅读:183      评论:0      收藏:0      [点我收藏+]

标签:序列   seq   重置   

问题一:如何重置oracle序列
oracle序列创建以后,如果想重置序列从 0 开始,逐渐递增1,可以采用如下存储过程:

create or replace
procedure reset_seq( p_seq_name in varchar2 )
is
    l_val number;
begin
    execute immediate
    ‘select ‘ || p_seq_name || ‘.nextval from dual‘ INTO l_val;

    execute immediate
    ‘alter sequence ‘ || p_seq_name || ‘ increment by -‘ || l_val || 
                                                          ‘ minvalue 0‘;

    execute immediate
    ‘select ‘ || p_seq_name || ‘.nextval from dual‘ INTO l_val;

    execute immediate
    ‘alter sequence ‘ || p_seq_name || ‘ increment by 1 minvalue 0‘;
end;
/

执行传入序列名称即可:
execute reset_seq(‘test_seq’);
即可

参考: click here

oracle 序列重置

标签:序列   seq   重置   

原文地址:http://blog.csdn.net/topwqp/article/details/46623507

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!