Oracle其实在11.1.0.6中已经推出了这个功能,不过11.1.0.6中还存在bug。这里简单介绍一下11.2中的REMAP_TABLE功能。
看一个简单的例子:
SQL> select * from v$version;
BANNER
--------------------------------------------------------------------------------
Oracle Database11gEnterprise Edition Release11.2.0.1.0 - 64bit Production
PL/SQL Release 11.2.0.1.0 - Production
CORE 11.2.0.1.0 Production
TNS for Linux: Version 11.2.0.1.0 - Production
NLSRTL Version 11.2.0.1.0 - Production
SQL> create table t
2 (id number,
3 name varchar2(30));
表已创建。
SQL> insert into t
2 select rownum, tname
3 from tab;
已创建11行。
SQL> commit;
提交完成。
SQL> create index ind_t_id
2 on t (id);
索引已创建。
下面导出T表:
SQL> host expdp yangtk/yangtk directory=d_output dumpfile=t.dp tables=t
Export: Release11.2.0.1.0 - Production on星期五6月4 23:31:50 2010
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
连接到: Oracle Database11gEnterprise Edition Release11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
启动"YANGTK"."SYS_EXPORT_TABLE_01": yangtk/******** directory=d_output dumpfile=t.dp tables=t
正在使用BLOCKS方法进行估计...
处理对象类型TABLE_EXPORT/TABLE/TABLE_DATA
使用BLOCKS方法的总估计: 128 KB
处理对象类型TABLE_EXPORT/TABLE/TABLE
处理对象类型TABLE_EXPORT/TABLE/INDEX/INDEX
处理对象类型TABLE_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
. .导出了"YANGTK"."T" 5.562 KB 11行
已成功加载/卸载了主表"YANGTK"."SYS_EXPORT_TABLE_01"
******************************************************************************
YANGTK.SYS_EXPORT_TABLE_01的转储文件集为:
/home/oracle/t.dp
作业"YANGTK"."SYS_EXPORT_TABLE_01"已于23:31:59成功完成
利用REMAP_TABLE将导入表重新映射到T_NEW表中:
SQL> host impdp yangtk/yangtk directory=d_output dumpfile=t.dp remap_table=t:t_new
Import: Release11.2.0.1.0 - Production on星期五6月4 23:32:19 2010
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
连接到: Oracle Database11gEnterprise Edition Release11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
已成功加载/卸载了主表"YANGTK"."SYS_IMPORT_FULL_01"
启动"YANGTK"."SYS_IMPORT_FULL_01": yangtk/******** directory=d_output dumpfile=t.dp remap_table=t:t_new
处理对象类型TABLE_EXPORT/TABLE/TABLE
处理对象类型TABLE_EXPORT/TABLE/TABLE_DATA
. .导入了"YANGTK"."T_NEW" 5.562 KB 11行
处理对象类型TABLE_EXPORT/TABLE/INDEX/INDEX
ORA-31684:对象类型INDEX:"YANGTK"."IND_T_ID"已存在
处理对象类型TABLE_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
ORA-39111:跳过从属对象类型INDEX_STATISTICS,基本对象类型INDEX:"YANGTK"."IND_T_ID"已存在
作业"YANGTK"."SYS_IMPORT_FULL_01"已经完成,但是有2个错误(于23:32:22完成)
SQL> select count(*) from t_new;
COUNT(*)
----------
11
REMAP_TABLE成功,T_NEW表创建,而且数据已经导入,不过可以看到,索引并没有别创建,不过这并不难理解,因为同名索引已经被创建,因此索引显然不能导入,下面删除索引:
SQL> drop table t_new purge;
表已删除。
SQL> drop index ind_t_id;
索引已删除。
再次执行导入操作:
SQL> host impdp yangtk/yangtk directory=d_output dumpfile=t.dp remap_table=t:t_new
Import: Release11.2.0.1.0 - Production on星期五6月4 23:32:54 2010
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
连接到: Oracle Database11gEnterprise Edition Release11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
已成功加载/卸载了主表"YANGTK"."SYS_IMPORT_FULL_01"
启动"YANGTK"."SYS_IMPORT_FULL_01": yangtk/******** directory=d_output dumpfile=t.dp remap_table=t:t_new
处理对象类型TABLE_EXPORT/TABLE/TABLE
处理对象类型TABLE_EXPORT/TABLE/TABLE_DATA
. .导入了"YANGTK"."T_NEW" 5.562 KB 11行
处理对象类型TABLE_EXPORT/TABLE/INDEX/INDEX
处理对象类型TABLE_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
作业"YANGTK"."SYS_IMPORT_FULL_01"已于23:32:58成功完成
SQL> select table_name, index_name
2 from user_indexes
3 where index_name = 'IND_T_ID';
TABLE_NAME INDEX_NAME
------------------------------ ------------------------------
T IND_T_ID
索引也成功导入,但是检查后发现,索引仍然创建到T表上,并没有因为使用了REMAP_TABLE而建立在T_NEW表中。
因此,至少在11.2.0.1中,REMAP_TABLE只对表和数据有效,而对索引无效,而且使用REMAP_TABLE对于原表仍然存在的情况下要小心,因为REMAP_TABLE操作很可能导致源表发生导入操作,导致一些非预期的对象被导入,比如:
SQL> alter table t add check (id > 0);
表已更改。
SQL> host expdp yangtk/yangtk directory=d_output dumpfile=t.dp tables=t reuse_dumpfiles=y
Export: Release11.2.0.1.0 - Production on星期五6月4 23:51:13 2010
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
连接到: Oracle Database11gEnterprise Edition Release11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
启动"YANGTK"."SYS_EXPORT_TABLE_01": yangtk/******** directory=d_output dumpfile=t.dp tables=t reuse_dumpfiles=y
正在使用BLOCKS方法进行估计...
处理对象类型TABLE_EXPORT/TABLE/TABLE_DATA
使用BLOCKS方法的总估计: 128 KB
处理对象类型TABLE_EXPORT/TABLE/TABLE
处理对象类型TABLE_EXPORT/TABLE/INDEX/INDEX
处理对象类型TABLE_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
处理对象类型TABLE_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
. .导出了"YANGTK"."T" 5.562 KB 11行
已成功加载/卸载了主表"YANGTK"."SYS_EXPORT_TABLE_01"
******************************************************************************
YANGTK.SYS_EXPORT_TABLE_01的转储文件集为:
/home/oracle/t.dp
作业"YANGTK"."SYS_EXPORT_TABLE_01"已于23:51:23成功完成
SQL> drop table t_new purge;
表已删除。
SQL> host impdp yangtk/yangtk directory=d_output dumpfile=t.dp remap_table=t:t_new
Import: Release11.2.0.1.0 - Production on星期五6月4 23:55:51 2010
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
连接到: Oracle Database11gEnterprise Edition Release11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
已成功加载/卸载了主表"YANGTK"."SYS_IMPORT_FULL_01"
启动"YANGTK"."SYS_IMPORT_FULL_01": yangtk/******** directory=d_output dumpfile=t.dp remap_table=t:t_new
处理对象类型TABLE_EXPORT/TABLE/TABLE
处理对象类型TABLE_EXPORT/TABLE/TABLE_DATA
. .导入了"YANGTK"."T_NEW" 5.562 KB 11行
处理对象类型TABLE_EXPORT/TABLE/INDEX/INDEX
ORA-31684:对象类型INDEX:"YANGTK"."IND_T_ID"已存在
处理对象类型TABLE_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
处理对象类型TABLE_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
ORA-39111:跳过从属对象类型INDEX_STATISTICS,基本对象类型INDEX:"YANGTK"."IND_T_ID"已存在
作业"YANGTK"."SYS_IMPORT_FULL_01"已经完成,但是有2个错误(于23:55:55完成)
SQL> col search_condition format a20
SQL> select table_name, constraint_name, search_condition
2 from user_constraints
3 where table_name = 'T';
TABLE_NAME CONSTRAINT_NAME SEARCH_CONDITION
------------------------------ ------------------------------ --------------------
T SYS_C0011261 id > 0
T SYS_C0011277 id > 0
在这个例子中,就由于约束是系统名称,导致在执行REMAP_TABLE导入后,同样的约束在源表上重复建立。
oracle视频教程请关注:http://u.youku.com/user_video/id_UMzAzMjkxMjE2.html