ORACLE impdp 导入数据

时间:2022-10-21 14:18:18

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;

Export: Release 10.2.0.1.0 - 64bit Production on 星期五, 06 1月, 2012 20:44:22

Copyright (c) 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

Starting "TUSER"."SYS_EXPORT_SCHEMA_01":  tuser/******** directory=dir_dump dumpfile=expdp.dmp schemas=tuser

Estimate in progress using BLOCKS method...

Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA

Total estimation using BLOCKS method: 128 KB

Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA

Processing object type SCHEMA_EXPORT/TABLE/TABLE

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

Processing object type SCHEMA_EXPORT/TABLE/COMMENT

. . exported "TUSER"."TAB1"                               5.25 KB       5 rows

. . exported "TUSER"."TAB2"                              5.296 KB      10 rows

Master table "TUSER"."SYS_EXPORT_SCHEMA_01" successfully loaded/unloaded

******************************************************************************

Dump file set for TUSER.SYS_EXPORT_SCHEMA_01 is:

/home/oracle/expdp.dmp

Job "TUSER"."SYS_EXPORT_SCHEMA_01" successfully completed at 20:47:29

2.3 查看已有两张表的数据

SQL> select * from tab1;

A   B

--- ----

1   11

2   22

3   33

4   44

5   55

SQL> select * from tab2;

A   B

--- ----

1   aa

2   bb

3   cc

4   dd

5   ee

6   ff

7   gg

8   hh

9   ii

10  jj

10 rows selected

3 replace

3.1 插入数据

SQL> insert into tab1 (a, b) values (6, 66);

1 row inserted

SQL> commit;

Commit complete

SQL> select * from tab1;

A   B

--- ----

1   11

2   22

3   33

4   44

5   55

6   66

6 rows selected

3.2 导入数据

[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 (c) 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;

Import: Release 10.2.0.1.0 - 64bit Production on 星期五, 06 1月, 2012 21:34:20

Copyright (c) 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

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 21:34:25

注意:即使表结构发生了变化,只要表名不发生变化。导入这个表时,就会被跳过。

5 append

5.1 删除部分数据

SQL> delete tab1 where a = 1;

1 row deleted

SQL> delete tab2 where a = 2;

1 row deleted

SQL> commit;

Commit complete

SQL> select * from tab1;

A   B

--- ----

2   22

3   33

4   44

5   55

SQL> select * from tab2;

A   B

--- ----

1   aa

3   cc

4   dd

5   ee

6   ff

7   gg

8   hh

9   ii

10  jj

9 rows selected

5.2 导入数据

[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 (c) 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;

Import: Release 10.2.0.1.0 - 64bit Production on 星期五, 06 1月, 2012 21:59:19

Copyright (c) 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-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_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;

Import: Release 10.2.0.1.0 - 64bit Production on 星期五, 06 1月, 2012 22:18:21

Copyright (c) 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

. . 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_03" completed with 2 error(s) at 22:18:28

注意:新插入的数据将丢失。

6.3 改表结构

SQL> alter table tab1 add (C varchar2(4));

Table altered

6.4 再导入数据

[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 (c) 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错误。看来导入导出前后的表结构不能发生变化。

ORACLE impdp 导入数据的更多相关文章

  1. Oracle impdp导入数据临时表空间与undo表空间爆满解决实例

    Oracle impdp导入数据临时表空间与undo表空间爆满解决实例 [日期:2018-01-24] 来源:Linux社区  作者:rangle [字体:大 中 小]   针对Oracle数据迁移, ...

  2. Oracle IMPDP导入数据案例之注意事项(undo/temp)

    针对Oracle数据迁移,我们可能会用到expdp/impdp的方式,有时候需要大表.lob字段等可能会消耗过大的临时表空间和undo表空间,所以一般我们根据导出日志,在导入前适当调整表空间大小.否则 ...

  3. Oracle逻辑导入数据(IMP/IMPDP)

    使用IMPDP导入数据的前提是数据是使用EMPDP导出的,同样也是在DOS窗口下直接输入IMPDP和登录数据库的用户名,即可导人数据. impdp导到指定用户下: impdp student/1234 ...

  4. Oracle使用——impdp导入数据时数据表已经存在

    背景 在做数据迁移时,需要将不同地方的dmp文件整合到一个数据库中,在导入时,目标表已经存在,该如何把数据追加进入目标表中 方法介绍 当使用IMPDP完成数据库导入时,如遇到表已存在时,Oracle提 ...

  5. oracle impdp导入时 提示“ORA-39002: 操作无效 ORA-39070: 无法打开日志文件 ”

    第一步:首先使用DBA权限的用户创建directory,我使用system ,可以在服务器本地创建,也可以远程连接sqlplus进行创建,使用的将是服务器上面的路径.要确保创建directory时,操 ...

  6. oracle impdp 导入

    用imp语法导入dmp文件: imp mdm/mdm@SYSWARE  file= ‪E:\Product\9y5s\5.MDM\20161024.DMP  full=y 报错 IMP-00002:无 ...

  7. Oracle Sqlload 导入数据

    sqlload导入数据具有快,简单,无需校验等方便,多说无益 1 首先,oracle数据库要有这么个表,用来接收数据.我这里这个uuid是序列生成的,当然也可以sqlload导入时候分配uuid -- ...

  8. Oracle快速导入数据工具

    sqlldr是oracle自带的快速导入批量数据的工具,常用于性能测试.考虑手工构造控制文件较为繁琐,因此使用脚本完成批量数据的自动导入. 基本知识 sqlldr命令语法 sqlldr dbname/ ...

  9. Oracle导出导入数据

    Oracle数据导入导出imp/exp就相当与oracle数据还原与备份, 利用这个功能你可以构建俩个相同的数据库,一个用来测试,一个用来正式使用. 可以在SQLPLUS.EXE或者DOS(命令行)中 ...

随机推荐

  1. 【原】KMeans与深度学习模型结合提高聚类效果

    这几天在做用户画像,特征是用户的消费商品的消费金额,原始数据(部分)是这样的: id goods_name goods_amount 男士手袋 1882.0 淑女装 2491.0 女士手袋 345.0 ...

  2. 大数据时代的IT架构设计

    大数据时代的IT架构设计(来自互联网.银行等领域的一线架构师先进经验分享) IT架构设计研究组 编著   ISBN 978-7-121-22605-2 2014年4月出版 定价:49.00元 208页 ...

  3. spring生命周期

    Github地址 最近在整合mybatis-spring. 公司里面已经有一个叫做kylin-datasource的开发包,以前能够提供master和slave2个数据源,最近更新了2.0版本,支持自 ...

  4. tinyxml2简单使用

    引入头文件 <span style="font-size:18px;">#include "HelloWorldScene.h" #include ...

  5. AJAX如何接收JSON数据

    简介 在我们了解如何使用AJAX返回JSON数据的时候要先明白下列几点 1. JSON如何来表示对象的 2. JSON如何来表示数组的 var object = { "labId" ...

  6. strutx&period;xml中配置文件的讲解

    Struts2框架的核心就是struts.xml文件了,该文件主要负责管理Struts的2的业务控制组件的核心内容.为了避免struts.xml的文件国 语庞大和臃肿,我们可以通过把一个struts. ...

  7. PHP 7&period;3 我们将迎来灵活的 heredoc 和 nowdoc 句法结构

    php.net RFC 频道已经公布了 PHP 7.3 的 Heredoc 和 Nowdoc 语法更新,此次更新专注于代码可读性: Heredoc 和 Nowdoc 有非常严格的语法,有些时候这令很多 ...

  8. hdu-2072(字典树)

    字典树模板题 代码 #include<iostream> #include<algorithm> #include<cstdio> #include<cstr ...

  9. ef 数据库连接字符串加密

    public testContext() : base(GetConnection(), true) { } public static DbConnection GetConnection() { ...

  10. Gym - 100989M(dp)

    George met AbdelKader in the corridor of the CS department busy trying to fix a group of incorrect e ...