发布网友 发布时间:2022-05-02 21:04
共3个回答
懂视网 时间:2022-05-03 01:26
假设需要修改的序列名:seq_name
1、select seq_name.nextval from dual; //假设得到结果5656
2、alter sequence seq_name increment by -5655 //注意是-(n-1)
3、select seq_name.nextval from dual; //再查一遍,走一下,重置为1了
4、alter sequence seq_name increment by 1; //还原
可以写个存储过程,以下是完整的存储过程,然后调用传参即可:
1 create or replace procedure seq_reset(v_seqname varchar2) 2 as cur_seq number(28); 3 tsql varchar2(200); 4 begin 5 execute immediate ‘select ‘ || v_seqname || ‘.nextval from dual‘ into cur_seq; 6 cur_seq:=-(cur_seq-1); 7 tsql:=‘alter sequence ‘ || v_seqname || ‘ increment by ‘ || cur_seq; 8 execute immediate tsql; 9 execute immediate ‘select ‘ || v_seqname || ‘.nextval from dual‘ into cur_seq; 10 tsql:=‘alter sequence ‘ || v_seqname || ‘ increment by 1‘; 11 execute immediate tsql; 12 end seq_reset;
需要调用时,执行(如sequence名称为SEQ_QT_PRCS_ID):
1 BEGIN 2 seq_reset(‘SEQ_QT_PRCS_ID‘); 3 END;
转载自《Oracle重置序列(不删除重建方式)》
【转】Oracle重置序列(不删除重建方式)
标签:hive res nextval _id alt 存储 logs sele span
热心网友 时间:2022-05-02 22:34
(1)删除sequence热心网友 时间:2022-05-02 23:52
删了sequence再重新创建序列。