ORACLE impdp 导入数据

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 导出数据

[[email protected] ~]$ 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 导入数据

[[email protected] ~]$ 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。

[[email protected] ~]$ 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 导入数据

[[email protected] ~]$ 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 再导入数据

[[email protected] ~]$ 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 导入数据

[[email protected] ~]$ 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 再导入数据

[[email protected] ~]$ 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错误。看来导入导出前后的表结构不能发生变化。

时间: 2024-12-22 23:46:30

ORACLE impdp 导入数据的相关文章

Oracle 导出导入数据

最近用到Oracle导出导入数据,在网上看了别人的一些文章,总结如下: Oracle导出导出有两中方式:一.利用exp imp导出导入:二.利用Oracel数据泵expdp impdp导出导入. 一.利用exp imp导出导入 exp imp 语法如下: exp: 1) 将数据库orcl完全导出 exp system/[email protected] file=d:\orcl_bak.dmp full=y 2) 将数据库中system用户的表导出 exp system/[email prote

oracle imp导入数据到另一个表空间

http://blog.163.com/[email protected]/blog/static/7156283420100531431855/ 1.在第一个数据库导出数据:qlyg_xs_db_chinatelecom_0910191029.dmp(用户为QLYG_XS) 2.将qlyg_xs_db_chinatelecom_0910191029.dmp 扶着到第二个数据库所在主机上 3.第二个数据库建立需要导入的表空间和用户QLYGKQ,QLYGKQ1(用户QLYGKQ1的默认表空间为QL

oracle sqlldr导入数据

背景 900W数据的TXT文本,文件内容各字段以"|"分隔,使用nevicat导入太慢 解决办法 使用sqlldr导入数据, 1)建立配置文件test.ctl [[email protected] ~]$ cat test.ctlload datainfile 'data.txt' into table CMCCfields terminated by "|"(id,phone,service_id,time,cmcc_num,cmcc_s) 解释:data.txt

oracle文本导入数据具体步骤和出现部分乱码处理方法

第一步,先将要导入的数据准备 第二步 将xlsx数据另存为txt文档 数据准备好了,现在可以导入到数据库里面了 第四步,打开文本导入器,将准备好的数据文本导入进去,具体效果如下图 第五步,选择要导入的表和对应的字段 第六步,就是点击导入了.也可以点击查看导入脚本 OK,导入部分已经结束了.如果导入脚本和导入数据部分出现乱码具体如下图: 我的是前一百条数据没问题,但后面全部都乱码了. 解决方案是:将xlsx另存为的时候选择文本文件,编码格式不用修改,不要改成UTF-8 或者其他的. 原文地址:ht

oracle impdp导入数据库报ora-14460错误

数据库版本: 源库:11.2.0.4 目的库:11.2.0.1 操作如下: 将源库expdp导出来的数据导入到目的库时,有分区的表报如下错误 ORA-14460: only one COMPRESS or NOCOMPRESS clause may be specified 解决方法: 在impdp命令加transform=segment_attributes:n参数即可 impdp username/password directory=impdp_dir dumpfile=*.dmp tra

Oracle 数据库导入数据和编码问题

配置 control 文件: load data characterset utf8 append into table role_res_gold fields terminated by ';' TRAILING NULLCOLS ( F_USERNAME , F_RES_TYPE , F_INDEX , F_NAME , F_COUNT , F_GAIN_TYPE CONSTANT "aa", //CONSTANT 是关键字,用常量替换行里面内容 F_CONSUME_TYPE F

Oracle imp 导入数据出现 ORA-12560

错误如下: D:\software\xfwebdb2015-05-11\autobackup>imp Import: Release 10.2.0.1.0 - Production on 星期三 5月 13 19:36:10 2015 Copyright (c) 1982, 2005, Oracle.  All rights reserved. 用户名: zfzb口令: IMP-00058: 遇到 ORACLE 错误 12560ORA-12560: TNS: 协议适配器错误IMP-00000:

Oracle 命令导入数据

1.用命令进入sqlplus: sqlplus 用户名/密码@127.0.0.1:1521/orcl 2.执行sql文件 sql>@D:/lanxi_his_data/V_JH_VISITINFO.sql

expdp、impdp数据泵导出导入数据

1.创建逻辑目录,该命令并不会创建正在的目录(请先创建真正的目录),以system管理员创建逻辑目录. sql>sqlplus system/[email protected] as sysdba sql>create directory dump_dir as 'd:\expdb'; 2.查看管理员目录(同时查看操作系统是否创建了该目录,oracle并不会关心是否创建了该目录,如果目录不存在,则会出错) sql>select * from dba_directories; 3.给需要操