[20190530]ORACLE 18c - ALTER SEQUENCE RESTART.txt

[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

posted @ 2019-05-31 08:47 lfree 阅读(...) 评论(...) 编辑 收藏