Oracle导出序列seq01时,得到创建seq01的语句,起始值(start with)并不等于源库创建seq01时的起始值,而是大于等于源库下一次执行seq01.nextval得到的值。
所以,迁移sequence时不需要在目标库上设置sequence,只要从源库导出sequence,在导入目标库即可。
例如:
1、如果源库创建seq01时用nocache,导出的创建seq01的start with,就等于源库下一次执行seq01.nextval的值:
create sequence SEQ_TEST_01
minvalue 1
maxvalue 999999999
start with 1
increment by 1
nocache;SQL> select SEQ_TEST_01.nextval from dual;
NEXTVAL
----------
1
导出的SEQ_TEST_01为:
create sequence EULAR_DEV.SEQ_TEST_01
minvalue 1
maxvalue 999999999
start with 2
increment by 1
nocache;
源库和目标库下次执行select SEQ_TEST_01.nextval from dual;时都将得到2。
2、如果源库创建seq01是用cache n,例如cache 20,导出的创建seq01的start with,就大于源库下一次执行seq01.nextval的值,大多少和cache值有关。
create sequence EULAR_DEV.SEQ_TEST_01
minvalue 1
maxvalue 999999999
start with 1
increment by 1
cache 50;SQL> select SEQ_TEST_01.nextval from dual;
NEXTVAL
----------
1
导出的SEQ_TEST_01为:
create sequence EULAR_DEV.SEQ_TEST_01
minvalue 1
maxvalue 999999999
start with 51
increment by 1
cache 50;
源库下次执行select SEQ_TEST_01.nextval from dual;时,将得到2,目标库下次执行select SEQ_TEST_01.nextval from dual;时,将得到51。