1 table_exists_action参数说明
使用imp进行数据导入时,若表已经存在,要先drop掉表,再进行导入。
而使用impdp完成数据库导入时,若表已经存在,有四种的处理方式:
1) skip:默认操作
2) replace:先drop表,然后创建表,最后插入数据
3) append:在原来数据的基础上增加数据
4) truncate:先truncate,然后再插入数据
2 实验预备
2.1 sys用户创建目录对象,并授权
SQL> create directory dir_dump as ‘/home/oracle’;
Directory created
SQL> grant read, write on directory dir_dump to tuser;
Grant succeeded
2.2 导出数据
[oracle@cent4 ~]\( expdp tuser/tuser directory=dir_dump dumpfile=expdp.dmp schemas=tuser;</p> <p>Export: Release 10.2.0.1.0 - 64bit Production on 星期五, 06 1月, 2012 20:44:22</p> <p>Copyright (c) 2003, 2005, Oracle. All rights reserved.</p> <p>Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - 64bit Production</p> <p>With the Partitioning, OLAP and Data Mining options</p> <p>Starting "TUSER"."SYS_EXPORT_SCHEMA_01": tuser/ directory=dir_dump dumpfile=expdp.dmp schemas=tuser</p> <p>Estimate in progress using BLOCKS method...</p> <p>Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA</p> <p>Total estimation using BLOCKS method: 128 KB</p> <p>Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA</p> <p>Processing object type SCHEMA_EXPORT/TABLE/TABLE</p> <p>Processing object type SCHEMA_EXPORT/TABLE/INDEX/INDEX</p> <p>Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT</p> <p>Processing object type SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS</p> <p>Processing object type SCHEMA_EXPORT/TABLE/COMMENT</p> <p>. . exported "TUSER"."TAB1" 5.25 KB 5 rows</p> <p>. . exported "TUSER"."TAB2" 5.296 KB 10 rows</p> <p>Master table "TUSER"."SYS_EXPORT_SCHEMA_01" successfully loaded/unloaded</p> <p></p> <p>Dump file set for TUSER.SYS_EXPORT_SCHEMA_01 is:</p> <p> /home/oracle/expdp.dmp</p> <p>Job "TUSER"."SYS_EXPORT_SCHEMA_01" successfully completed at 20:47:29</p> <p>2.3 查看已有两张表的数据</p> <p>SQL> select * from tab1;</p> <p>A B</p> <p>--- ----</p> <p>1 11</p> <p>2 22</p> <p>3 33</p> <p>4 44</p> <p>5 55</p> <p>SQL> select * from tab2;</p> <p>A B</p> <p>--- ----</p> <p>1 aa</p> <p>2 bb</p> <p>3 cc</p> <p>4 dd</p> <p>5 ee</p> <p>6 ff</p> <p>7 gg</p> <p>8 hh</p> <p>9 ii</p> <p>10 jj</p> <p>10 rows selected</p> <p>3 replace</p> <p>3.1 插入数据</p> <p>SQL> insert into tab1 (a, b) values (6, 66);</p> <p>1 row inserted</p> <p>SQL> commit;</p> <p>Commit complete</p> <p>SQL> select * from tab1;</p> <p>A B</p> <p>--- ----</p> <p>1 11</p> <p>2 22</p> <p>3 33</p> <p>4 44</p> <p>5 55</p> <p>6 66</p> <p>6 rows selected</p> <p>3.2 导入数据</p> <p>[oracle@cent4 ~]\) impdp tuser/tuser directory=dir_dump dumpfile=expdp.dmp schemas=tuser table_exists_action=replace;
Import: Release 10.2.0.1.0 - 64bit Production on 星期五, 06 1月, 2012 20:53:09
Copyright © 2003, 2005, Oracle. All rights reserved.
Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - 64bit Production
With the Partitioning, OLAP and Data Mining options
Master table “TUSER”.“SYS_IMPORT_SCHEMA_01” successfully loaded/unloaded
Starting “TUSER”.“SYS_IMPORT_SCHEMA_01”: tuser/ directory=dir_dump dumpfile=expdp.dmp schemas=tuser table_exists_action=replace
Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
Processing object type SCHEMA_EXPORT/TABLE/TABLE
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
. . imported “TUSER”.“TAB1” 5.25 KB 5 rows
. . imported “TUSER”.“TAB2” 5.296 KB 10 rows
Processing object type SCHEMA_EXPORT/TABLE/INDEX/INDEX
Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
Processing object type SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
Job “TUSER”.“SYS_IMPORT_SCHEMA_01” successfully completed at 20:53:25
3.3 再查看数据
SQL> select * from tab1;
A B
— —-
1 11
2 22
3 33
4 44
5 55
查看数据,这时没有第六条数据。
另外新建的表,在备份中没有,这个表并不会被覆盖。
4 skip
drop表tab1,tab2。
[oracle@cent4 ~]\( impdp tuser/tuser directory=dir_dump dumpfile=expdp.dmp schemas=tuser;</p> <p>Import: Release 10.2.0.1.0 - 64bit Production on 星期五, 06 1月, 2012 21:34:20</p> <p>Copyright (c) 2003, 2005, Oracle. All rights reserved.</p> <p>Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - 64bit Production</p> <p>With the Partitioning, OLAP and Data Mining options</p> <p>Master table "TUSER"."SYS_IMPORT_SCHEMA_01" successfully loaded/unloaded</p> <p>Starting "TUSER"."SYS_IMPORT_SCHEMA_01": tuser/ directory=dir_dump dumpfile=expdp.dmp schemas=tuser</p> <p>Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA</p> <p>Processing object type SCHEMA_EXPORT/TABLE/TABLE</p> <p>Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA</p> <p>. . imported "TUSER"."TAB1" 5.25 KB 5 rows</p> <p>. . imported "TUSER"."TAB2" 5.296 KB 10 rows</p> <p>Processing object type SCHEMA_EXPORT/TABLE/INDEX/INDEX</p> <p>Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT</p> <p>Processing object type SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS</p> <p>Job "TUSER"."SYS_IMPORT_SCHEMA_01" successfully completed at 21:34:25</p> <p>注意:即使表结构发生了变化,只要表名不发生变化。导入这个表时,就会被跳过。</p> <p>5 append</p> <p>5.1 删除部分数据</p> <p>SQL> delete tab1 where a = 1;</p> <p>1 row deleted</p> <p>SQL> delete tab2 where a = 2;</p> <p>1 row deleted</p> <p>SQL> commit;</p> <p>Commit complete</p> <p>SQL> select * from tab1;</p> <p>A B</p> <p>--- ----</p> <p>2 22</p> <p>3 33</p> <p>4 44</p> <p>5 55</p> <p>SQL> select * from tab2;</p> <p>A B</p> <p>--- ----</p> <p>1 aa</p> <p>3 cc</p> <p>4 dd</p> <p>5 ee</p> <p>6 ff</p> <p>7 gg</p> <p>8 hh</p> <p>9 ii</p> <p>10 jj</p> <p>9 rows selected</p> <p>5.2 导入数据</p> <p>[oracle@cent4 ~]\) impdp tuser/tuser directory=dir_dump dumpfile=expdp.dmp schemas=tuser table_exists_action=append;
Import: Release 10.2.0.1.0 - 64bit Production on 星期五, 06 1月, 2012 21:50:40
Copyright © 2003, 2005, Oracle. All rights reserved.
Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - 64bit Production
With the Partitioning, OLAP and Data Mining options
Master table “TUSER”.“SYS_IMPORT_SCHEMA_01” successfully loaded/unloaded
Starting “TUSER”.“SYS_IMPORT_SCHEMA_01”: tuser/ directory=dir_dump dumpfile=expdp.dmp schemas=tuser table_exists_action=append
Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
Processing object type SCHEMA_EXPORT/TABLE/TABLE
ORA-39152: Table “TUSER”.“TAB1” exists. Data will be appended to existing table but all dependent metadata will be skipped due to table_exists_action of append
ORA-39152: Table “TUSER”.“TAB2” exists. Data will be appended to existing table but all dependent metadata will be skipped due to table_exists_action of append
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
ORA-31693: Table data object “TUSER”.“TAB1” failed to load/unload and is being skipped due to error:
ORA-00001: unique constraint (TUSER.PK_TAB1) violated
ORA-31693: Table data object “TUSER”.“TAB2” failed to load/unload and is being skipped due to error:
ORA-00001: unique constraint (TUSER.PK_TAB2) violated
Processing object type SCHEMA_EXPORT/TABLE/INDEX/INDEX
Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
Processing object type SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
Job “TUSER”.“SYS_IMPORT_SCHEMA_01” completed with 4 error(s) at 21:50:45
注意:只要append数据出错,比如唯一键错误,这时什么数据都不能插入了。
5.3 修改表结构

SQL> alter table tab1 add (C varchar2(4));
Table altered
5.4 再导入数据
[oracle@cent4 ~]\( impdp tuser/tuser directory=dir_dump dumpfile=expdp.dmp schemas=tuser table_exists_action=append;</p> <p>Import: Release 10.2.0.1.0 - 64bit Production on 星期五, 06 1月, 2012 21:59:19</p> <p>Copyright (c) 2003, 2005, Oracle. All rights reserved.</p> <p>Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - 64bit Production</p> <p>With the Partitioning, OLAP and Data Mining options</p> <p>Master table "TUSER"."SYS_IMPORT_SCHEMA_01" successfully loaded/unloaded</p> <p>Starting "TUSER"."SYS_IMPORT_SCHEMA_01": tuser/ directory=dir_dump dumpfile=expdp.dmp schemas=tuser table_exists_action=append</p> <p>Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA</p> <p>Processing object type SCHEMA_EXPORT/TABLE/TABLE</p> <p>ORA-39152: Table "TUSER"."TAB1" exists. Data will be appended to existing table but all dependent metadata will be skipped due to table_exists_action of append</p> <p>ORA-39152: Table "TUSER"."TAB2" exists. Data will be appended to existing table but all dependent metadata will be skipped due to table_exists_action of append</p> <p>Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA</p> <p>ORA-39014: One or more workers have prematurely exited.</p> <p>ORA-39029: worker 1 with process name "DW01" prematurely terminated</p> <p>ORA-31671: Worker process DW01 had an unhandled exception.</p> <p>ORA-00600: internal error code, arguments: [qerxtAgentOpen_911], [3], [2], [], [], [], [], []</p> <p>ORA-06512: at "SYS.KUPW\)WORKER“, line 1345
ORA-06512: at line 2
Job ”TUSER“.”SYS_IMPORT_SCHEMA_01“ stopped due to fatal error at 21:59:57
这时居然出现600错误。
6 truncate
6.1 插入部分数据
SQL> insert into tab1 (a, b) values (6, 66);
1 row inserted
SQL> commit;
Commit complete
6.2 导入数据
[oracle@cent4 ~]\( impdp tuser/tuser directory=dir_dump dumpfile=expdp.dmp schemas=tuser table_exists_action=truncate;</p> <p>Import: Release 10.2.0.1.0 - 64bit Production on 星期五, 06 1月, 2012 22:18:21</p> <p>Copyright (c) 2003, 2005, Oracle. All rights reserved.</p> <p>Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - 64bit Production</p> <p>With the Partitioning, OLAP and Data Mining options</p> <p>Master table "TUSER"."SYS_IMPORT_SCHEMA_03" successfully loaded/unloaded</p> <p>Starting "TUSER"."SYS_IMPORT_SCHEMA_03": tuser/ directory=dir_dump dumpfile=expdp.dmp schemas=tuser table_exists_action=truncate</p> <p>Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA</p> <p>Processing object type SCHEMA_EXPORT/TABLE/TABLE</p> <p>ORA-39153: Table "TUSER"."TAB1" exists and has been truncated. Data will be loaded but all dependent metadata will be skipped due to table_exists_action of truncate</p> <p>ORA-39153: Table "TUSER"."TAB2" exists and has been truncated. Data will be loaded but all dependent metadata will be skipped due to table_exists_action of truncate</p> <p>Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA</p> <p>. . imported "TUSER"."TAB1" 5.25 KB 5 rows</p> <p>. . imported "TUSER"."TAB2" 5.296 KB 10 rows</p> <p>Processing object type SCHEMA_EXPORT/TABLE/INDEX/INDEX</p> <p>Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT</p> <p>Processing object type SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS</p> <p>Job "TUSER"."SYS_IMPORT_SCHEMA_03" completed with 2 error(s) at 22:18:28</p> <p>注意:新插入的数据将丢失。</p> <p>6.3 改表结构</p> <p>SQL> alter table tab1 add (C varchar2(4));</p> <p>Table altered</p> <p>6.4 再导入数据</p> <p>[oracle@cent4 ~]\) impdp tuser/tuser directory=dir_dump dumpfile=expdp.dmp schemas=tuser table_exists_action=truncate;
Import: Release 10.2.0.1.0 - 64bit Production on 星期五, 06 1月, 2012 22:22:02
Copyright © 2003, 2005, Oracle. All rights reserved.
Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - 64bit Production
With the Partitioning, OLAP and Data Mining options
Master table ”TUSER“.”SYS_IMPORT_SCHEMA_03“ successfully loaded/unloaded
Starting ”TUSER“.”SYS_IMPORT_SCHEMA_03“: tuser/ directory=dir_dump dumpfile=expdp.dmp schemas=tuser table_exists_action=truncate
Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
Processing object type SCHEMA_EXPORT/TABLE/TABLE
ORA-39153: Table ”TUSER“.”TAB1“ exists and has been truncated. Data will be loaded but all dependent metadata will be skipped due to table_exists_action of truncate
ORA-39153: Table ”TUSER“.”TAB2“ exists and has been truncated. Data will be loaded but all dependent metadata will be skipped due to table_exists_action of truncate
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
ORA-39014: One or more workers have prematurely exited.
ORA-39029: worker 1 with process name ”DW01“ prematurely terminated
ORA-31671: Worker process DW01 had an unhandled exception.
ORA-00600: internal error code, arguments: [qerxtAgentOpen_911], [3], [2], [], [], [], [], []
ORA-06512: at ”SYS.KUPW$WORKER“, line 1345
ORA-06512: at line 2
Job ”TUSER“.”SYS_IMPORT_SCHEMA_03“ stopped due to fatal error at 22:22:42
此时,一样也发生了600错误。看来导入导出前后的表结构不能发生变化。

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/198726.html