需求是这样的:想将A库的某schema中的一部分表导入到B库的某schema中。
第一可以想到的是使用expdp工具,但是如何只挑选某些表呢,通过查看官方文档,include参数可以实现该需求。
include语法如下:
1INCLUDE = object_type[:name_clause] [, ...]
query具体的说明请参见官方文档。
现测试如下:
1、数据库版本,


1 > select * from v$version; 2 3 BANNER 4 -------------------------------------------------------------------------------- 5 Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production 6 PL/SQL Release 11.2.0.4.0 - Production 7 CORE 11.2.0.4.0 Production 8 9 TNS for 64-bit Windows: Version 11.2.0.4.0 - Production 10 NLSRTL Version 11.2.0.4.0 - Production
2、在scott中新建三个测试表,为了能够使用query参数,此处特意以“test+数字”命名测试表


1 > create table scott.test1 (id number(4), description varchar2(100)); 2 3 Table created 4 5 SQL> create table scott.test2 (id number(4), description varchar2(100)); 6 7 Table created 8 9 SQL> create table scott.test3 (id number(4), description varchar2(100)); 10 11 Table created
3、给三个测试表插入数据


1 > select * from scott.test1; 2 3 ID DESCRIPTION 4 ----- -------------------------------------------------------------------------------- 5 1 test table no.1 6 2 test table no.1 7 8 SQL> select * from scott.test2; 9 10 ID DESCRIPTION 11 ----- -------------------------------------------------------------------------------- 12 1 test table no.2 13 2 test table no.2 14 3 test table no.2 15 16 SQL> select * from scott.test3; 17 18 ID DESCRIPTION 19 ----- -------------------------------------------------------------------------------- 20 1 test table no.3 21 2 test table no.3 22 3 test table no.3 23 4 test table no.3
4、新建被导入的schema


1 > create user scott_test identified by scotttest default tablespace users; 2 3 User created
5、仅导出scott中的test1、test2、test3三张表
expdp \"/as sysdba\" dumpfile=scotttesttbl.dmp schema=scott include=table:\"like '%TEST%'\"
7、从上图看,确实仅导出了刚才新建的三张表,我们可以将这个dmp文件倒回到scott_test用户下验证
先给scott_test用户赋予resource权限
> grant resource to scott_test;
Grant succeeded
通过remap_schema将scott用户下的表导入scott_test用户下
impdp \"/as sysdba\" dumpfile=scotttesttbl.dmp remap_schema=scott:soctt_test
8、查看scott_test用户下的所有表
> grant connect to scott_test; Grant succeeded ========================== > select user from dual; USER ------------------------------ SCOTT_TEST ========================== > select * from user_tables; TABLE_NAME TABLESPACE_NAME CLUSTER_NAME IOT_NAME STATUS PCT_FREE ... ------------------------------ ------------------------------ ------------------------------ ------------------------------ -------- ---------- ... TEST3 USERS VALID 10 ... TEST1 USERS VALID 10 ... TEST2 USERS VALID 10 ... SQL>
实验成功。
花絮:开始以为实现该功能是需要query参数,后来发现不行,query是实现更细致力度的参数,可以筛选表中符合查询条件的某些内容。