impdp 中的remap方式

impdp 中的remap方式
impdp 中要是没有remap方式,那么个人认为datapump 将是一个死板的工具。
remap_table方式
语法格式:REMAP_TABLE=[schema.]old_tablename[.partition]:new_tablename
在hr 模式中根据employees 创建如下一张表。
SQL>create table emp as select * from employees where 1=2;
执行导入操作,tables 中指定了employees,因为dumpfile table.dmp
中除了employees 表中的数据以外,还有其他表的数据。关键是remap_table
参数的使用把employees 表中的数据从映射到emp 表,并且我们还使用了
conntent=data_only 参数,因为emp表已经存在,我们需要导入的只是数据。
C:\Users\hello>impdp hr/hr tables=employees remap_table=employees:emp dumpfile=dmp_dir:table.dmp nologfile=yes content=data_only
Import: Release 11.2.0.1.0 - Production on Sun Jun 24 09:35:22 2012
Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Master table "HR"."SYS_IMPORT_TABLE_01" successfully loaded/unloaded
Starting "HR"."SYS_IMPORT_TABLE_01":  hr/******** tables=employees remap_table=employees:emp dumpfile=dmp_dir:table.dmp nologfile=yes content=data_only
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
. . imported "HR"."EMP"                                  16.80 KB     107 rows
Job "HR"."SYS_IMPORT_TABLE_01" successfully completed at 09:35:26
导入成功,下面确定数据是否存在于remap_table 参数指定的表中。
SQL>select count(*) from emp;
  COUNT(*)
----------
       107
remap_schema方式
语法格式:REMAP_SCHEMA=source_schema:target_schema
我们需要把使用schemas mode 导出的数据,重新导入到另外一个模式中,这时候我们
可以使用remap_schema 参数,为了能够使用remap_schema 方式导入数据,用户应该
事先获得datapump_imp_full_database 角色。下面指定数据的导入。
C:\Users\hello>impdp hr/hr schemas=hr remap_schema=hr:test dumpfile=dmp_dir:hr_schema.dmp logfile=dmp_dir:remap_schema.log
Import: Release 11.2.0.1.0 - Production on Sun Jun 24 09:50:43 2012
Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Master table "HR"."SYS_IMPORT_SCHEMA_01" successfully loaded/unloaded
Starting "HR"."SYS_IMPORT_SCHEMA_01":  hr/******** schemas=hr remap_schema=hr:test dumpfile=dmp_dir:hr_schema.dmp logfile=dmp_dir:remap_schema.log
Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
Processing object type SCHEMA_EXPORT/SEQUENCE/SEQUENCE
Processing object type SCHEMA_EXPORT/TABLE/TABLE
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
. . imported "TEST"."COUNTRIES"                          6.367 KB      25 rows
. . imported "TEST"."DEPARTMENTS"                        7.007 KB      27 rows
. . imported "TEST"."EMPLOYEES"                          16.80 KB     107 rows
. . imported "TEST"."JOBS"                               6.984 KB      19 rows
. . imported "TEST"."JOB_HISTORY"                        7.054 KB      10 rows
. . imported "TEST"."LOCATIONS"                          8.273 KB      23 rows
. . imported "TEST"."REGIONS"                            5.476 KB       4 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
Processing object type SCHEMA_EXPORT/VIEW/VIEW
Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINT
Processing object type SCHEMA_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
Job "HR"."SYS_IMPORT_SCHEMA_01" successfully completed at 09:50:53
导入成功以后确定,test 模式中的数据。表中的数据,约束,索引等都是存在的。
SQL> select count(*) from employees;
  COUNT(*)
----------
       107
SQL> drop table employees;
drop table employees
           *
ERROR at line 1:
ORA-02449: unique/primary keys in table referenced by foreign keys
SQL> select index_name from user_indexes
  2  where table_name = 'EMPLOYEES';
INDEX_NAME
------------------------------------------------------------
EMP_EMP_ID_PK
EMP_EMAIL_UK
remap_tablespace 方式
在hr 模式中创建emp 表。
SQL> create table emp tablespace users as select * from employees;
Table created.
将emp 表导出。
C:\Users\hello>expdp hr/hr tables=emp dumpfile=dmp_dir:emp_table.dmp nologfile=yes
创建 一个新的用户并赋予相应的权限,注意这里的默认永久表空间是test而不是users.
SQL> create user testing
  2  identified by testing
  3  default tablespace test
  4  temporary tablespace temp;
User created.
SQL> alter user testing default tablespace test quota 20m on test;
User altered.
SQL> grant connect to testing;
Grant succeeded.
SQL> grant create table to testing;
Grant succeeded.
执行导入发现如下的错误。因为用户没有users 表空间的使用权,更不用说配额了。
C:\Users\hello>impdp hr/hr tables=emp remap_schema=hr:testing dumpfile=dmp_dir:emp_table.dmp nologfile=yes
ORA-39083: Object type TABLE:"TESTING"."EMP" failed to create with error:
ORA-01950: no privileges on tablespace 'USERS'
下面我们使用remap_tablespace 的方式来处理。将dumpfile 中对users 表空间的引用remap 到test 表空间。
C:\Users\hello>impdp hr/hr tables=emp remap_schema=hr:testing remap_tablespace=users:test dumpfile=dmp_dir:emp_table.dmp nologfile=yes
Import: Release 11.2.0.1.0 - Production on Sun Jun 24 10:59:25 2012
Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Master table "HR"."SYS_IMPORT_TABLE_01" successfully loaded/unloaded
Starting "HR"."SYS_IMPORT_TABLE_01":  hr/******** tables=emp remap_schema=hr:testing remap_tablespace=users:test dumpfile=dmp_dir:emp_table.dmp nologfile=yes
Processing object type TABLE_EXPORT/TABLE/TABLE
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
. . imported "TESTING"."EMP"                             16.79 KB     107 rows
Job "HR"."SYS_IMPORT_TABLE_01" successfully completed at 10:59:28
成功的导入了,确定一下testing模式中的数据。
SQL> select count(*) from emp;
  COUNT(*)
----------
       107
除了上述演示的remap 方式以外还有一个remap_datafile,用来将dumpfile 中包含的数据文件 路径,remap 到新的数据数据路径。该参数只有当使用full 模式导入的时候才可以使用。

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/26110315/viewspace-733694/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/26110315/viewspace-733694/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值