乐趣区

关于oracle:批量生成序列重置SQL

产品迭代,同用一个库,或者迁徙后仅清理数据,导致序列几十亿,可能会有一些影响,因而重置,如果生产沿用一些货色,审慎操作。

-- 执行命令生成后果
SELECT 'alter sequence' || SEQUENCE_OWNER || '.' || SEQUENCE_NAME ||'increment by' || (SQ.MIN_VALUE - SQ.LAST_NUMBER + 500) || ';'||chr(10)||
       'select' || SEQUENCE_OWNER || '.' || SEQUENCE_NAME ||'.nextval from dual;' ||chr(10)||
       'alter sequence' || SEQUENCE_OWNER || '.' || SEQUENCE_NAME ||'increment by' || SQ.INCREMENT_BY || ';' cmd
  FROM DBA_SEQUENCES SQ
 WHERE SEQUENCE_OWNER = '&USERNAME'
   AND SQ.LAST_NUMBER > 10000;
-- 替换变量 USERNAME 为你数据库用户 
退出移动版