[20190530]ORACLE 18c - ALTER SEQUENCE RESTART.txt
--//之前遇到要重置或者調整seq比較麻煩,我有時候採用比較粗暴的方式就是刪除重建.
--//18c提供方式重置,本身測試看看.
1.環境:
SYSTEM@xxxxxx> select BANNER from v$version;
BANNER
----------------------------------------------------------------------
Oracle Database 18c Enterprise Edition Release 18.0.0.0.0 - Production
SYSTEM@xxxxxx> CREATE SEQUENCE Seq1 START WITH 1 INCREMENT BY 1 MINVALUE 1 MAXVALUE 9999;
Sequence created.
SYSTEM@xxxxxx> SELECT Seq1.nextval FROM dual;
NEXTVAL
----------
1
SYSTEM@xxxxxx> SELECT Seq1.nextval FROM dual;
NEXTVAL
----------
2
--//批量執行以下:
$ seq 500 | xargs -I{} echo select seq1.nextval from dual\; | rlsql system/xxx@xxxxxx
SYSTEM@xxxxxx> SELECT Seq1.nextval FROM dual;
NEXTVAL
----------
503
--//如今已經到503.
SYSTEM@xxxxxx> ALTER SEQUENCE Seq1 RESTART;
Sequence altered.
SYSTEM@xxxxxx> SELECT Seq1.nextval FROM dual;
NEXTVAL
----------
1
--//如今回到1的位置.還能夠這樣執行:
SYSTEM@xxxxxx> ALTER SEQUENCE Seq1 RESTART START WITH 1500;
Sequence altered.
SYSTEM@xxxxxx> SELECT Seq1.nextval FROM dual;
NEXTVAL
----------
1500
$ rlsql system/xxx@xxxx <<EOF
> $( seq 5 | xargs -I{} echo 'select seq1.nextval from dual;')
> EOF
sql