您的位置:首页 > 数据库 > Oracle

分区表的导入导出 expdp&impdp Oracle 11.2.0.4

2015-12-29 19:44 513 查看
分区表的导入导出

数据库版本:
Oracle 11.2.0.4

expdp  导出 schema 。

当前有两个分区表
TABLE_NAME PARTITION_NAME TABLESPACE_NAME

------------------------------ ------------------------------ ------------------------------

TABLE1 SYS_P57
NEW

TABLE1 SYS_P66NEW

TABLE2 T_TEST_201503
T3

TABLE2 T_TEST_MAX
T

TABLE2 T_TEST_201510
T4

TABLE2 T_TEST_201412
T2

TABLE2 T_TEST_201406
T1

21 rows selected.

SQL> l

  1* select TABLE_NAME,PARTITION_NAME,TABLESPACE_NAME from USER_TAB_PARTITIONS order by table_name

  

当前有两个分区表
table1 是创建在一个表空间中的分区表,有多个分区。
table2 是将有多个分区表空间的分区表,多个分区对应多个表空间。

涉及的表空间
new、T、T1、T2、T3、T4

涉及的用户
new

/**********对new用户进行导出,再远端数据库中导入  schema level

create directory EXPDP as '/backup/expdp';

grant read,write on directory EXPDP to system;

导出整个 new schema:

export NLS_LANG=AMERICAN_AMERICA.ZHS16GBK

expdp system/oracle  directory=EXPDP schemas=new dumpfile=20151228expnew.dmp logfile=20151228expnew.log

expdp system/oracle  directory=EXPDP schemas=new dumpfile=20151228expnewtab3.dmp logfile=20151228expnewtab3.log

. . exported "NEW"."PF_MEMBER_BANKCARD"                      0 KB       0 rows

. . exported "NEW"."PF_MEMBER_CORPORATION"                   0 KB       0 rows

. . exported "NEW"."PF_MEMBER_LINKINFO"                      0 KB       0 rows

. . exported "NEW"."TABLE2":"T_TEST_201503"                  0 KB       0 rows

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

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

Dump file set for SYSTEM.SYS_EXPORT_SCHEMA_01 is:

  /backup/expdp/20151228expnew.dmp

Job "SYSTEM"."SYS_EXPORT_SCHEMA_01" successfully completed at Mon Dec 28 10:25:40 2015 elapsed 0 00:01:21

目标库导入new schema:

create directory EXPDP as '/backup/expdp';

grant read,write on directory EXPDP to system;

export NLS_LANG=AMERICAN_AMERICA.ZHS16GBK
impdp system/oracle  directory=EXPDP dumpfile=20151228expnew.dmp schemas=new remap_schema=new:demo remap_tablespace=new:demo logfile=20151228expnew.log 

没有创建table2所需要的表空间的时候 报错:

[oracle@primary ~]$ export NLS_LANG=AMERICAN_AMERICA.ZHS16GBK

[oracle@primary ~]$ impdp system/oracle  directory=EXPDP dumpfile=20151228expnew.dmp schemas=new remap_schema=new:demo remap_tablespace=new:demo logfile=20151228expnew.log

ORA-39171: Job is experiencing a resumable wait.

ORA-01658: unable to create INITIAL extent for segment in tablespace DEMO

ORA-39083: Object type TABLE:"DEMO"."TABLE2" failed to create with error:

ORA-00959: tablespace 'T1' does not exist

Failing sql is:

CREATE TABLE "DEMO"."TABLE2" ("TABLE_ID" NUMBER(8,0), "SUB_DATE" DATE, "VALUE" NUMBER(8,0)) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255  STORAGE( BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT) TABLESPACE "DEMO"  PARTITION BY RANGE ("SUB_DATE")
 (PARTITION "T_TEST_201406"  VALUES LESS THAN (TO_DATE(' 2014-06-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALEN

Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA

. . imported "DEMO"."PF_AGREEMENT"                           0 KB       0 rows

. . imported "DEMO"."PF_MEMBER_BANKCARD"                     0 KB       0 rows

. . imported "DEMO"."PF_MEMBER_CORPORATION"                  0 KB       0 rows

. . imported "DEMO"."PF_MEMBER_LINKINFO"                     0 KB       0 rows

Job "SYSTEM"."SYS_IMPORT_SCHEMA_01" completed with 5 error(s) at Mon Dec 28 10:55:08 2015 elapsed 0 00:07:31

因为 没有对应的表空间,所以导入失败。

SQL> select * from table1;

  TABLE_ID SUB_DATE     VALUE

---------- ------------ ----------
1 01-APR-14
11
1 01-MAY-14
11
1 01-JUN-14
11
1 01-JUL-14
11

SQL> select * from table2;

select * from table2

              *

ERROR at line 1:

ORA-00942: table or view does not exist

换个方法试试 将多个表空间的内容 导入到一个表空间。适用于 一个scheman中有多个表,分布在不同的表空间中,最终汇总到一个表空间。

参考:
impdp ctais3/oracle DIRECTORY=DATA_PUMP_DIR dumpfile=ctais2.dmp remap_schema=ctais2:ctais3 remap_tablespace='(EXAMPLE:ZHANGQIAOC,USERS:ZHANGQIAOC)'

impdp system/oracle  directory=EXPDP dumpfile=20151228expnew.dmp schemas=new remap_schema=new:demo remap_tablespace='new:demo,T:demo,T1:demo,T2:demo,T3:demo,T4:demo' logfile=20151228expnew.log

drop user demo cascade;

create user demo identified by demo default tablespace demo;

[oracle@primary ~]$ impdp system/oracle  directory=EXPDP dumpfile=20151228expnew.dmp schemas=new remap_schema=new:demo remap_tablespace='new:demo,T:demo,T1:demo,T2:demo,T3:demo,T4:demo' logfile=20151228expnew.log

Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA

. . imported "DEMO"."PF_AGREEMENT"                           0 KB       0 rows

. . imported "DEMO"."PF_MEMBER_BANKCARD"                     0 KB       0 rows

. . imported "DEMO"."PF_MEMBER_CORPORATION"                  0 KB       0 rows

. . imported "DEMO"."PF_MEMBER_LINKINFO"                     0 KB       0 rows

. . imported "DEMO"."TABLE2":"T_TEST_201503"                 0 KB       0 rows

Processing object type SCHEMA_EXPORT/TABLE/COMMENT

ORA-39082: Object type ALTER_PROCEDURE:"DEMO"."P_BALANCE_ONLINE_EXPORT" created with compilation warnings

ORA-39082: Object type ALTER_PROCEDURE:"DEMO"."P_CARD_ENCRYPT" created with compilation warnings

Job "SYSTEM"."SYS_IMPORT_SCHEMA_01" completed with 3 error(s) at Mon Dec 28 11:02:12 2015 elapsed 0 00:00:18

这么 调整之后,就可以将多个表空间的内容导入到一个表空间中了。

总结:
如果原schema中 包含了分区表,在进行导出的时候,是可以正常导出的。
使用 schemas=new remap_schema=new:demo remap_tablespace='new:demo,T:demo,T1:demo,T2:demo,T3:demo,T4:demo' 可以将一个schema中分布在不同多个表空间中的表 对应到新的schema下的 一个表空间中。
建议,在进行导出之前,最好先查一下,需要导出的schema中是否有分区表:
select table_name,PARTITION_NAME,TABLESPACE_NAME from USER_TAB_PARTITIONS order by table_name;
建议:在进行导入之前,如果确定包含分区表,最好是创建根之前对象的表空间一样名称的表空间。
如果不创建,或者创建对应表空间的话,使用
remap_tablespace='new:demo,T:T_new,T1:T1_new,T2:T2_new,T3:T3_new,T4:T4_new' 方式来对应---创建后依然是分区表
如果加上  partition_options=merge 选项后 变成了一个普通表

/**********分区表的导出 table level:
导出整个表
export NLS_LANG=AMERICAN_AMERICA.ZHS16GBK
expdp system/oracle DIRECTORY=EXPDP DUMPFILE=table2full.dmp TABLES=new.table2 logfile=table2full.log tables参数格式为user.table
导出一个分区
expdp system/oracle DIRECTORY=EXPDP DUMPFILE=table2one.dmp TABLES='new.table2:T_TEST_201510' logfile=table2one.log
导出多个分区
expdp system/oracle DIRECTORY=EXPDP DUMPFILE=table2some.dmp TABLES='new.table2:T_TEST_201510,new.table2:T_TEST_201412,new.table2:T_TEST_201503' logfile=table2some.log
expdp system/oracle DIRECTORY=EXPDP DUMPFILE=table2someo.dmp TABLES='new.table2:T_%' logfile=table2someo.log    使用通配符 跟exp imp的用法一致
导出部分数据
select * from table2  where to_char(SUB_DATE,'YYYY')>2014;
expdp system/oracle DIRECTORY=EXPDP DUMPFILE=table2data.dmp TABLES='new.table2' logfile=table2data.log query=\"where to_char\(SUB_DATE,\'YYYY\'\)\>2014\"

/**********Impdp 导入 schemas level:
如果分区表的表空间不存在
impdp system/oracle  directory=EXPDP dumpfile=20151228expnew.dmp schemas=new remap_schema=new:demo remap_tablespace=new:demo logfile=20151228expnew.log 会不导入该表,其他表可以导入
如果目标库上分区表的表空间 跟 源数据库上分区表的名称 创建的一致
impdp system/oracle  directory=EXPDP dumpfile=20151228expnew.dmp schemas=new remap_schema=new:demo remap_tablespace=new:demo logfile=20151228expnew.log  可以全部导入
将分区表聚合到一个表空间
impdp system/oracle  directory=EXPDP dumpfile=20151228expnew.dmp schemas=new remap_schema=new:demo remap_tablespace='new:demo,T:demo,T1:demo,T2:demo,T3:demo,T4:demo' logfile=20151228expnew.log

/**********impdp 导入分区表 table level:
分区表不存在
drop table table2 purge;
impdp system/oracle  directory=EXPDP dumpfile=20151228expnew.dmp schemas=new remap_schema=new:demo remap_tablespace=new:demo tables='new.table2' logfile=20151228impnew.table2.log

[oracle@primary ~]$ impdp system/oracle  directory=EXPDP dumpfile=20151228expnew.dmp schemas=new remap_schema=new:demo remap_tablespace=new:demo tables=table2 logfile=20151228impnew.table2.log

Import: Release 11.2.0.4.0 - Production on Mon Dec 28 13:02:36 2015

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production

With the Partitioning, Automatic Storage Management, OLAP, Data Mining

and Real Application Testing options

UDI-00010: multiple job modes requested, schema and tables.

不支持 schemas 和 tables 同时存在

这样解决
源分区表 聚合到一个表空间
impdp system/oracle  directory=EXPDP dumpfile=20151228expnew.dmp remap_schema=new:demo remap_tablespace='new:demo,T:demo,T1:demo,T2:demo,T3:demo,T4:demo' tables=new.table2 logfile=20151228impnew.table2.log
说明 不设置参数partition_options 这样聚合之后,demo.table2 依然是一个分区表,只不过所有的数据都在一个表空间中。partition_options 默认是none的。

impdp system/oracle  directory=EXPDP dumpfile=20151228expnew.dmp remap_schema=new:demo remap_tablespace='new:demo,T:demo,T1:demo,T2:demo,T3:demo,T4:demo' tables=new.table2 partition_options=merge  logfile=20151228impnew.table2.log
说明 加入参数 partition_options=merge 选项后demo.table2 变成了一个普通表。

补充
partition_options=departition 这个参数是将各个分区 变成一个新的表。
impdp system/oracle  directory=EXPDP dumpfile=20151228expnew.dmp remap_schema=new:demo remap_tablespace='new:demo,T:demo,T1:demo,T2:demo,T3:demo,T4:demo' tables=new.table2 partition_options=departition  logfile=20151228impnew.table2.log
SQL> select table_name from user_tables;
TABLE_NAME
------------------------------
TABLE2_T_TEST_MAX
TABLE2_T_TEST_201510
TABLE2_T_TEST_201503
TABLE2_T_TEST_201412
TABLE2_T_TEST_201406

源分区表 和 目标分区表 相同表空间
1、先创建 表空间
查看分区表空间的对象关系 使用如下语句 在源数据库上查询:
select TABLE_NAME,PARTITION_NAME,TABLESPACE_NAME from USER_TAB_PARTITIONS order by table_name;
注意,分区表所依赖的表空间 并不单单指的是 分区的表空间,还包含 那个母表的表空间。
创建语句
##create tablespace new datafile '+DATA' size 200M; -----本例中,将new 表空间 remap_tablespace 到demo表空间中
create tablespace T datafile '+DATA' size 20M;
create tablespace T1 datafile '+DATA' size 20M;
create tablespace T2 datafile '+DATA' size 20M;
create tablespace T3 datafile '+DATA' size 20M;
create tablespace T4 datafile '+DATA' size 20M;
2、创建分区表(11g可不创建)
SELECT DBMS_METADATA.GET_DDL('TABLE',u.table_name) FROM USER_TABLES u where u.table_name='&name'; 获得DDL创建 需要先创建表空间
或者
从dump文件中获得 biao table2的DDL语句
impdp system/oracle directory=EXPDP dumpfile=20151228expnew.dmp sqlfile=EXPDP:table2_ddl.sql tables=new.table2
3、导入表
impdp system/oracle  directory=EXPDP dumpfile=20151228expnew.dmp remap_schema=new:demo remap_tablespace=new:demo tables=new.table2 logfile=20151228impnew.table2_sametbs.log

源分区表 和 目标分区表 不同表空间
1、先创建 表空间
创建语句
##create tablespace new datafile '+DATA' size 200M; -----本例中,将new 表空间 remap_tablespace 到demo表空间中
create tablespace TN datafile '+DATA' size 20M;
create tablespace TN1 datafile '+DATA' size 20M;
create tablespace TN2 datafile '+DATA' size 20M;
create tablespace TN3 datafile '+DATA' size 20M;
create tablespace TN4 datafile '+DATA' size 20M;
2、创建分区表(11g可不创建)
SELECT DBMS_METADATA.GET_DDL('TABLE',u.table_name) FROM USER_TABLES u where u.table_name='&name'; 获得DDL创建 需要先创建表空间
或者
从dump文件中获得 biao table2的DDL语句
impdp system/oracle directory=EXPDP dumpfile=20151228expnew.dmp sqlfile=EXPDP:table2_ddl.sql tables=new.table2
3、导入表
impdp system/oracle  directory=EXPDP dumpfile=20151228expnew.dmp remap_schema=new:demo remap_tablespace='new:demo,T:TN,T1:TN1,T2:TN2,T3:TN3,T4:TN4' tables=new.table2 logfile=20151228impnew.table2_sametbs_n.log

如果只是导 入分区的话 
impdp system/oracle  directory=EXPDP dumpfile=20151228expnew.dmp remap_schema=new:demo remap_tablespace='new:demo,T:TN,T1:TN1,T2:TN2,T3:TN3,T4:TN4' tables='new.table2:T_TEST_201503,new.table2:T_TEST_201412' logfile=20151228impnew.table2_pn.log
impdp system/oracle  directory=EXPDP dumpfile=20151228expnew.dmp remap_schema=new:demo remap_tablespace='new:demo,T:TN,T1:TN1,T2:TN2,T3:TN3,T4:TN4' tables='new.table2:T_TEST_%' logfile=20151228impnew.table2_pn.log
impdp system/oracle  directory=EXPDP dumpfile=20151228expnew.dmp remap_schema=new:demo remap_tablespace=new:demo tables='new.table2:T_TEST_%' logfile=20151228impnew.table2_sametbs.log

/****************/将原来在一个表空间中的分区表,导入为每个分区一个表空间的表,目标也在一个新的表空间中

原来表table3 

SQL> select * from table3;

  TABLE_ID SUB_DATE     VALUE

---------- ------------ ----------
1 01-APR-14
11
1 01-MAY-14
11
1 01-JUN-14
11
1 01-JUL-14
11
1 01-AUG-14
11
1 01-AUG-14
11
1 01-SEP-14
11
1 01-OCT-14
11
1 01-NOV-14
11
1 01-JUN-15
11
1 01-JUL-15
11
1 01-AUG-15
11
1 01-SEP-15
11
1 01-OCT-15
11
1 01-NOV-15
11
1 01-DEC-15
11
1 01-JUN-16
11
 

目的 将table3迁移成分区表

方案一  手动先创建 目标分区表(表空间是必须要先创建好的)

1、创建一个分区表 demo.table3 on 目标库

select dbms_metadata.get_ddl('TABLE','TABLE3','DEMO') from dual; 

##create tablespace demo datafile '+DATA' size 200M; -----本例中,将 demo 表空间为默认表空间 不需要再次创建

create tablespace T datafile '+DATA' size 20M;

create tablespace T1 datafile '+DATA' size 20M;

create tablespace T2 datafile '+DATA' size 20M;

create tablespace T3 datafile '+DATA' size 20M;

create tablespace T4 datafile '+DATA' size 20M;

conn demo/demo

create table table3 (

   TABLE_ID NUMBER(8),

   SUB_DATE DATE,

   VALUE NUMBER(8)

)

PARTITION BY RANGE (SUB_DATE)

(

  PARTITION t_test_201406 VALUES LESS THAN (TO_DATE('2014-06-01 00:00:00','yyyy-mm-ddhh24:mi:ss')) TABLESPACE T1,

  PARTITION t_test_201412 VALUES LESS THAN (TO_DATE('2014-12-01 00:00:00','yyyy-mm-ddhh24:mi:ss')) TABLESPACE T2,

  PARTITION t_test_201503 VALUES LESS THAN (TO_DATE('2015-03-01 00:00:00','yyyy-mm-ddhh24:mi:ss')) TABLESPACE T3,

  PARTITION t_test_201510 VALUES LESS THAN (TO_DATE('2015-10-01 00:00:00','yyyy-mm-ddhh24:mi:ss')) TABLESPACE T4,

  PARTITION t_test_max   VALUES LESS THAN (MAXVALUE) TABLESPACE T

) ;

----注意 parttion是在 T%表空上的,但是 table3是在DEMO表空间中的。 可以创建新的分区名称 以及重新定义表空间的名称

2、导入

impdp system/oracle  directory=EXPDP dumpfile=20151228expnewtab3.dmp remap_schema=new:demo  tables='new.table3' table_exists_action=append logfile=20151228impnew.table3.log

[oracle@primary expdp]$ impdp system/oracle  directory=EXPDP dumpfile=20151228expnewtab3.dmp remap_schema=new:demo  tables='new.table3' table_exists_action=append logfile=20151228impnew.table3.log

Import: Release 11.2.0.4.0 - Production on Mon Dec 28 15:11:02 2015

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production

With the Partitioning, Automatic Storage Management, OLAP, Data Mining

and Real Application Testing options

Master table "SYSTEM"."SYS_IMPORT_TABLE_01" successfully loaded/unloaded

Starting "SYSTEM"."SYS_IMPORT_TABLE_01":  system/******** directory=EXPDP dumpfile=20151228expnewtab3.dmp remap_schema=new:demo tables=new.table3 table_exists_action=append logfile=20151228impnew.table3.log 

Processing object type SCHEMA_EXPORT/TABLE/TABLE

Table "DEMO"."TABLE3" 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

. . imported "DEMO"."TABLE3"                             6.195 KB      17 rows

Job "SYSTEM"."SYS_IMPORT_TABLE_01" successfully completed at Mon Dec 28 15:11:08 2015 elapsed 0 00:00:05

select * from table3 PARTITION(t_test_201406);

SQL> select * from table3 PARTITION(t_test_201406);

  TABLE_ID SUB_DATE     VALUE

---------- ------------ ----------
1 01-APR-14
11
1 01-MAY-14
11

3、导入到不同的表名称中

(1)创建表

create table tableN (

   TABLE_ID NUMBER(8),

   SUB_DATE DATE,

   VALUE NUMBER(8)

)

PARTITION BY RANGE (SUB_DATE)

(

  PARTITION t_test_1 VALUES LESS THAN (TO_DATE('2014-06-01 00:00:00','yyyy-mm-ddhh24:mi:ss')) TABLESPACE T1,

  PARTITION t_test_2 VALUES LESS THAN (TO_DATE('2014-12-01 00:00:00','yyyy-mm-ddhh24:mi:ss')) TABLESPACE T2,

  PARTITION t_test_3 VALUES LESS THAN (TO_DATE('2015-03-01 00:00:00','yyyy-mm-ddhh24:mi:ss')) TABLESPACE T3,

  PARTITION t_test_4 VALUES LESS THAN (TO_DATE('2015-10-01 00:00:00','yyyy-mm-ddhh24:mi:ss')) TABLESPACE T4,

  PARTITION t_test_max   VALUES LESS THAN (MAXVALUE) TABLESPACE T

) ;

(2) 导入

impdp system/oracle  directory=EXPDP dumpfile=20151228expnewtab3.dmp remap_schema=new:demo tables='new.table3' remap_tablespace='new:demo' remap_table='new.table3:tablen'  table_exists_action=append logfile=20151228impnew.table3.log

[oracle@primary expdp]$ impdp system/oracle  directory=EXPDP dumpfile=20151228expnewtab3.dmp remap_schema=new:demo tables='new.table3' remap_tablespace='new:demo' remap_table='new.table3:tablen'  table_exists_action=append logfile=20151228impnew.table3.log

Import: Release 11.2.0.4.0 - Production on Mon Dec 28 15:33:42 2015

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production

With the Partitioning, Automatic Storage Management, OLAP, Data Mining

and Real Application Testing options

Master table "SYSTEM"."SYS_IMPORT_TABLE_01" successfully loaded/unloaded

Starting "SYSTEM"."SYS_IMPORT_TABLE_01":  system/******** directory=EXPDP dumpfile=20151228expnewtab3.dmp remap_schema=new:demo tables=new.table3 remap_tablespace=new:demo remap_table=new.table3:tablen table_exists_action=append logfile=20151228impnew.table3.log 

Processing object type SCHEMA_EXPORT/TABLE/TABLE

Table "DEMO"."TABLEN" 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

. . imported "DEMO"."TABLEN"                             6.195 KB      17 rows

Job "SYSTEM"."SYS_IMPORT_TABLE_01" successfully completed at Mon Dec 28 15:33:44 2015 elapsed 0 00:00:02

注意 remap_table='new.table3:tablen'  这里 不要再tablen之前加用户名称,否则会创建 “username.tablen” 这样一个表

select * from tableN PARTITION(t_test_1);

SQL>  select * from tableN PARTITION(t_test_1);

  TABLE_ID SUB_DATE     VALUE

---------- ------------ ----------
1 01-APR-14
11
1 01-MAY-14
11

注意:
由于约束是系统名称,导致在执行REMAP_TABLE导入后,同样的约束在源表上重复建立

 
/**********impdp 分区表 追加:
1、按分区追加
清理分区:
alter table test truncate partiton a;
ALTER TABLE yourTable DROP PARTITION partionName1;
alter table table1 DROP PARTITION SYS_P41;

增加第一个分区
impdp system/oracle  directory=EXPDP dumpfile=20151228expnew.dmp remap_schema=new:demo remap_tablespace='new:demo'  tables='new.table1:P1' logfile=20151228impnew.table1_1.log

追加后面的分区
----impdp system/oracle  directory=EXPDP dumpfile=20151228expnew.dmp remap_schema=new:demo remap_tablespace='new:demo'  tables='new.table1:P1' table_exists_action=append参数 logfile=20151228impnew.table1_1.log
impdp system/oracle  directory=EXPDP dumpfile=20151228expnew.dmp remap_schema=new:demo remap_tablespace='new:demo'  tables='new.table1:SYS_P41'  table_exists_action=append参数 logfile=20151228impnew.table1_SYS_P41.log  切记,table_exists_action的参数
尽量不要使用replace 和 truncate
append 是为表增加数据;
truncate 是截断表,然后为其增加新数据;
replace  是删除已存在表,重新建表并追加数据。
或者
impdp system/oracle  directory=EXPDP dumpfile=20151228expnew.dmp remap_schema=new:demo remap_tablespace='new:demo'  tables='new.table1:SYS_P%'  table_exists_action=append参数 logfile=20151228impnew.table1_SYS_Pn.log 

参考:

exp/imp,expdp/impdp 与分区表有关的知识:使用exp -help 查看:

example: imp scott/tiger ignore=y tables=(emp,dept) full=n

               or tables=(t1:p1,t1:p2), if t1 is partitioned table

example: exp scott/tiger grants=y tables=(emp,dept,mgr)

               or tables=(t1:p1,t1:p2), if t1 is partitioned table

example: expdp scott/tiger dumpfile=scott.dmp directory=dmpdir schemas=scott   or tables=(t1:p1,t1:p2), if t1 is partitioned table

example: impdp scott/tiger directory=dmpdir dumpfile=scott.dmp

从转储文件中提取DDL。
如:impdp system/oracle directory=EXPDP dumpfile=20151228expnew.dmp sqlfile=EXPDP:table22.sql schemas=new 就是指将属于 new模式的所有DDL写入位于EXPDP的table22.sql文件中.

Expdp导出分区表的数据文件再Impdp导入到没分区的表的操作方法

 Article_Detail是个按时间的分区表:

导出的Bat如下:假设这个表有四个分区,且每个分区的NUM_ROWs至少有20万记录,导出参数tables=Article_Detail 表示每个分区都会导出20万条记录,实则导出的记录为80万。

expdp test/1234@orcl_test query=article_detail:\"where rownum<=200000 order by Article_Detail_ID desc\" tables=Article_Detail directory=TEST_DUMP_DIR dumpfile=Article_Detail_20W.dmp logfile=Article_Detail_20W.log compression=DATA_ONLY  content=DATA_ONLY parallel=2

 

导入:从分区表导出的文件里导入到非分区表,在导入的批处理里要有partition_options参数,partition_options=merge表示将四个分区的数据合并在一起。因为分区表中对应多个表空间,所以要remap_tablespace一下,导入脚本如下:

impdp test_2/1234@orcl_test2 directory=TEST_DUMP_DIR remap_schema=test:test_2 dumpfile=Article_Detail_20W.dmp logfile=Impdp_Article_Detail_20W.log table_exists_action=APPEND data_options=SKIP_CONSTRAINT_ERRORS parallel=2 Exclude=Trigger partition_options=merge
  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: