创建自增序列:
create sequence AutoID
start with 1 //根据需要自己可修改该数值
increment by 1 //步长值
minvalue 1
nomaxvalue
创建触发器:
create trigger AutoID_Trigger
before insert on Test_Table for each row
begin
select AutoID.nextval into :new.ID from dual;
end
重置序列:
假设需要修改的序列名:seq_name
获取seq_name的nextval值
SELECT seq_name.nextval FROM dual;
假设得到的结果是 555
调整增长值
ALTER SEQUENCE seq_name INCREMENT BY -554;
注意此处是 -(n-1)
重新获取seq_name的nextval值
SELECT seq_name.nextval FROM dual;
此时获取nextval就重置为1了
重新修改调整值为1
ALTER SEQUENCE seq_name INCREMENT BY 1;