expdp之include参数——实现表级别的expdp操作

本文介绍了如何使用Oracle的expdp工具,通过include参数来实现特定表级别的导出操作。在需求场景中,需要将A库schema中的部分表导入到B库的另一schema中。详细步骤包括创建测试表、插入数据、设置权限以及使用remap_schema选项进行数据导入,并验证了仅包含指定表的dmp文件能成功导入到目标schema。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

需求是这样的:想将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
View Code

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
View Code

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
View Code

4、新建被导入的schema

1 > create user scott_test identified by scotttest default tablespace users;
2 
3 User created
View Code

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是实现更细致力度的参数,可以筛选表中符合查询条件的某些内容。

 

转载于:https://www.cnblogs.com/xidabei/p/7553782.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值