使用数据泵导入数据,导入过程中没有任何错误,导入的记录数完全正常,但应用就是无法使用,取不到数据,找了很久都没找到原因,最后,发现是由于序列的问题引起的,发现导出和导入的值不一样,通过与开发沟通才明白,因为在导入数据时要对一些字段定义做了修改,所以先导入空表,然后再导入数据的,在向表插入数据时会插入序列,而序列是由触发器来产生的,从而导致两边的序列值不一致,引起记录的值有差异,找到原因就好办了,在导入数据前关闭所有的约束和触发器,导入数据成功后,再打开约束和触发器,连接应用测试,一切ok.
在目标库上建立数据泵目录
create directory dump_dir as '/oracle/ppp';
grant read,write on directory dump_dir to user;
在源库上导出数据:
expdp system/oracle directory=dump_dir dumpfile=user.dmp schemas=user logfile=user.log
导出表结构:
impdp system/oracle directory=dump_dir dumpfile=user.dmp sqlfile=user.sql logfile=userimp.log
在目标库上建立表
SQL>@/oracle/ppp/user.sql
导入数据前关闭约束和触发器:
SQL>set heading off
SQL>select 'alter table '||table_name||' disable constraint '||constraint_name||';' from user_constraints;
SQL>alter table table_name disable constraint constraint_name;
SQL>select 'alter trigger '||trigger_name||' disable;' from user_triggers;
SQL>alter trigger trigger_name disable;
导入数据:
export ORACLE_SID=SID
$impdp system/oracle directory=dump_dir dumpfile=javaoanew.dmp table_exists_action=append logfile=javaoaimpnew.log
导入数据后打开约束和触发器:
SQL>set heading off
SQL>select 'alter table '||table_name||' enable novalidate constraint '||constraint_name||';' from user_constraints;
SQL>alter table table_name enable novalidate constraint constraint_name;
SQL>select 'alter trigger '||trigger_name||' enable;' from user_triggers;
SQL>alter trigger trigger_name enable;
连接应用测试,一切OK.
在目标库上建立数据泵目录
create directory dump_dir as '/oracle/ppp';
grant read,write on directory dump_dir to user;
在源库上导出数据:
expdp system/oracle directory=dump_dir dumpfile=user.dmp schemas=user logfile=user.log
导出表结构:
impdp system/oracle directory=dump_dir dumpfile=user.dmp sqlfile=user.sql logfile=userimp.log
在目标库上建立表
SQL>@/oracle/ppp/user.sql
导入数据前关闭约束和触发器:
SQL>set heading off
SQL>select 'alter table '||table_name||' disable constraint '||constraint_name||';' from user_constraints;
SQL>alter table table_name disable constraint constraint_name;
SQL>select 'alter trigger '||trigger_name||' disable;' from user_triggers;
SQL>alter trigger trigger_name disable;
导入数据:
export ORACLE_SID=SID
$impdp system/oracle directory=dump_dir dumpfile=javaoanew.dmp table_exists_action=append logfile=javaoaimpnew.log
导入数据后打开约束和触发器:
SQL>set heading off
SQL>select 'alter table '||table_name||' enable novalidate constraint '||constraint_name||';' from user_constraints;
SQL>alter table table_name enable novalidate constraint constraint_name;
SQL>select 'alter trigger '||trigger_name||' enable;' from user_triggers;
SQL>alter trigger trigger_name enable;
连接应用测试,一切OK.
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/29099879/viewspace-776421/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/29099879/viewspace-776421/