这是序列脚本:
@H_502_13@CREATE SEQUENCE IDctr_seq MINVALUE 1 MAXVALUE 99 START WITH 1 INCREMENT BY 1 CACHE 10;然后这是代码,当序列达到最大值时,它尝试将值重置为1.如果代码有效,我稍后会将其转换为函数,但它会失败.
@H_502_13@declare seq_num number; exceed_maxvalue exception; pragma exception_init(exceed_maxvalue,-8004);begin seq_num := IDctr_seq.nextval; DBMS_OUTPUT.PUT_liNE(seq_num); exception when exceed_maxvalue then execute immediate 'sequence IDctr_seq increment by -99 minvalue 0'; execute immediate 'select IDctr_seq.nextval from dual'; execute immediate 'alter sequence IDctr_seq increment by 1 minvalue 0';end;如果我运行代码直到达到最大值,它不会产生错误,但它也不会将自身重置为1.
解决方法 这是 CYCLE关键字的用例;报价indicate that the sequence continues to generate values after reaching either its maximum or minimum value. After an ascending sequence reaches its maximum value,it generates its minimum value. After a descending sequence reaches its minimum,it generates its maximum value.
您的对象声明应该变为:
@H_502_13@CREATE SEQUENCE IDctr_seq MINVALUE 1 MAXVALUE 99 START WITH 1 INCREMENT BY 1 CACHE 10 CYCLE;这是一个较小序列的演示
@H_502_13@sql> create sequence test_seq start with 1 maxvalue 3 nocache cycle;Sequence created.sql> select test_seq.nextval from dual; NEXTVAL---------- 1sql> select test_seq.nextval from dual; NEXTVAL---------- 2sql> select test_seq.nextval from dual; NEXTVAL---------- 3sql> select test_seq.nextval from dual; NEXTVAL---------- 1 总结以上是内存溢出为你收集整理的oracle – 序列超过最大值时的异常处理全部内容,希望文章能够帮你解决oracle – 序列超过最大值时的异常处理所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)