测试环境:oracle 10.2.0.4 win 7 64bit
oracle 11.2.0.3
RHEL4.2 32bit
结论:1、从schema1中导入到schema2中,sequence的值会发生变化,但是变化是在导出过程中产生的,在导入
时会把变化值导入到schema2中。完成后两个schema的值还是一致的。
2、从schema1中导出,然后导入schema1中(table_exists_action=truncate),oracle10g在导入(注意
只是impdp时不变,expdp会发生变化的)前后不会发生变化,而oracle11g环境中是会发生变化的。
3、触发器禁用与否对sequence没有影响。
4、sequence值具体什么原因产生变化的,本人没做细致研究,望知晓的同学给予指导,谢谢!
补充:值变化与cache有关,这里设置cache为10,每次expdp/impdp的时候cache中的值会被舍弃,重
新导入一组cache。关闭cache可以解决该问题。
########################################################
Oracle 10g中的测试:
########################################################
1、创建sequence
CREATE SEQUENCE
sequence1
INCREMENT BY 1
START WITH
1
NOMAXVALUE
NOCYCLE
CACHE 10;
2、创建测试表
create table test(id number,wid number);
create table test1(id number);
3、创建触发器
Create or replace trigger trigger_test
before insert or update or delete
On test
Begin
Insert into test1
values(1);
End;
4、开始测试,往test表中多次插入数据:
SQL> insert into
test(id,wid)values(1,sequence1.nextval);
1 row inserted
SQL> commit;
Commit complete
SQL> select * from test;
ID WID
---------- ----------
1 5
2 6
1 11
1 23
1 25
SQL> select * from test1;
ID
----------
1
22
1
24
这个时候可以看出sequence的值为25.下一个值为26.
5、导出schema数据
C:\Users\ZhangNai>expdp system/password
schemas=SEQUENCE1 logfile=expdp.log directory=DP_DIR
dumpfile=expdp1.dmp
C:\Users\ZhangNai>impdp system/password
remap_schema=SEQUENCE1:SEQUENCE2 logfile=impdp.log directory=DP_DIR
dumpfile=expdp1.dmp
导入另一个schema,完成之后,进行查询:
SQL> select * from test;
ID WID
---------- ----------
1 5
2 6
1 11
1 23
1 25
SQL> select * from test1;
ID
----------
1
22
1
24
SQL> select SEQUENCE1.nextval from dual;
NEXTVAL
----------
31
查询源schema的nextval结果:
SQL> select SEQUENCE1.nextval from dual;
NEXTVAL
----------
31
6、从查询结果看,在数据完成EXPDP/IMPDP之后,源库和目标库的sequence是保持不表的,但是在EXPDP/IMPDP中
sequence值会发生变化,这个变化在源库和目标库保持一致。为了验证含有sequence语句的触发器对sequence是否有影响,将原有
触发器trigger_test删除,重新创建触发器:
create table test1(id number);
Create or replace trigger trigger_test1
before insert or update or delete
On test
Begin
Insert into test1
values(sequence1.nextval);
End;
然后重复上述的验证,结果和前面验证的结果一样:在数据完成EXPDP/IMPDP之后,源库和目标库的sequence是保持不表的,但是在EXPDP/IMPDP中
sequence值会发生变化,这个变化在源库和目标库保持一致。
7、在源schema:sequence1中进行多次数据插入:
SQL> insert into
test(id,wid)values(1,sequence1.nextval);
1 row inserted
SQL> /
1 row inserted
SQL> /
1 row inserted
SQL> commit;
Commit complete
SQL> select * from test;
ID WID
---------- ----------
1 5
2 6
1 11
1 23
1 25
1 33
1 35
1 37
1 39
9 rows selected
SQL> select * from test1;
ID
----------
1
22
1
24
32
34
36
38
8 rows selected
查看sequence值:当前值为39,next值为40
SQL> select SEQUENCE1.currval from dual;
CURRVAL
----------