批量生成序列重置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为你数据库用户

你可能感兴趣的:(oraclesql批量序列号)