oracle重建sequence
情况描述:使用expdp/impdp 导数据到开发库时,sequence引起ORA-00001 违反唯一约束条件。
解决:根据生产库重建开发库的sequence
1、删除开发库的sequence
生成删除开发库的sequence的sql:
select ‘drop sequence ‘||s.SEQUENCE_OWNER||’.’||s.SEQUENCE_NAME||’;’ from dba_sequences s where s.SEQUENCE_OWNER =UPPER(‘开发库用户’);
2、生成根据生产库来创建开发库的sequence的sql:
(以生产库的当前值为开发库的开始值)
select ‘create sequence ‘||‘开发库用户’||’.’||s.SEQUENCE_NAME||’ start with ‘||s.LAST_NUMBER||’ increment by ‘||s.INCREMENT_BY ||’ minvalue ‘|| s.MIN_VALUE||’ maxvalue ‘||s.MAX_VALUE||’ NOCACHE NOCYCLE NOORDER;’
from dba_sequences s where s.SEQUENCE_OWNER =UPPER(‘生产库用户’);
谨记:心存敬畏,行有所止。