阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

Oracle 11g expdp中query参数的使用

385次阅读
没有评论

共计 9600 个字符,预计需要花费 24 分钟才能阅读完成。

Oracle 11g expdp 中提供了 query 参数,可以在需要按条件导出表中部分数据时使用,它的使用就像是在 select 语句中的 where 条件使用一样。

数据库版本

linuxidc@ORCL>select * from v$version;

BANNER

——————————————————————————–

Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 – 64bit Production

PL/SQL Release 11.2.0.4.0 – Production

CORE11.2.0.4.0Production

TNS for Linux: Version 11.2.0.4.0 – Production

NLSRTL Version 11.2.0.4.0 – Production

创建测试表

linuxidc@ORCL>create table e1 (id number,name varchar2(20));

Table created.

linuxidc@ORCL>create table e2 (id number,birthday date);

Table created.

插入测试数据

linuxidc@ORCL>insert into e1 select level,lpad(level,20,’*’) from dual connect by level <= 100;

100 rows created.

linuxidc@ORCL>commit;

Commit complete.

linuxidc@ORCL>insert into e2 select level,sysdate-50+level from dual connect by level <= 100;

100 rows created.

linuxidc@ORCL>commit;

Commit complete.

创建目录

linuxidc@ORCL>create directory dir as ‘/home/oracle/’;

Directory created.

linuxidc@ORCL>host

测试使用 query 导出

注意:如果 query 条件在 parfile 中则不需要用 ’\’ 进行转义

[oracle@rhel6 ~]$ expdp zx/zx directory=dir dumpfile=e1.dmp tables=zx.e1 query=zx.e1:\”where id<=50\”

bash: =50″: No such file or directory

Export: Release 11.2.0.4.0 – Production on Thu Jul 21 14:23:11 2016

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, OLAP, Data Mining and Real Application Testing options

Starting “ZX”.”SYS_EXPORT_TABLE_01″:  zx/******** directory=dir dumpfile=e1.dmp tables=zx.e1 query=zx.e1:”where id<=50″

Estimate in progress using BLOCKS method…

Processing object type TABLE_EXPORT/TABLE/TABLE_DATA

Total estimation using BLOCKS method: 64 KB

Processing object type TABLE_EXPORT/TABLE/TABLE

. . exported “ZX”.”E1″                                  6.757 KB      50 rows

Master table “ZX”.”SYS_EXPORT_TABLE_01″ successfully loaded/unloaded

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

Dump file set for ZX.SYS_EXPORT_TABLE_01 is:

  /home/oracle/e1.dmp

Job “ZX”.”SYS_EXPORT_TABLE_01″ successfully completed at Thu Jul 21 14:23:26 2016 elapsed 0 00:00:11

exit

查询 scn 号

linuxidc@ORCL>select dbms_flashback.get_system_change_number from dual;

GET_SYSTEM_CHANGE_NUMBER

————————

 2179047

linuxidc@ORCL>select count(*) from e1;

  COUNT(*)

———-

      100

删除部分数据

linuxidc@ORCL>delete from e1 where id<20;

19 rows deleted.

linuxidc@ORCL>commit;

Commit complete.

linuxidc@ORCL>host

测试 query 及 flashback_scn

[oracle@rhel6 ~]$ expdp zx/zx directory=dir dumpfile=e1_1.dmp tables=zx.e1 query=zx.e1:\”where id\<=50\” flashback_scn=2179047

Export: Release 11.2.0.4.0 – Production on Thu Jul 21 14:25:41 2016

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, OLAP, Data Mining and Real Application Testing options

Starting “ZX”.”SYS_EXPORT_TABLE_01″:  zx/******** directory=dir dumpfile=e1_1.dmp tables=zx.e1 query=zx.e1:”where id<=50″ flashback_scn=2179047

Estimate in progress using BLOCKS method…

Processing object type TABLE_EXPORT/TABLE/TABLE_DATA

Total estimation using BLOCKS method: 64 KB

Processing object type TABLE_EXPORT/TABLE/TABLE

. . exported “ZX”.”E1″                                  6.757 KB      50 rows

Master table “ZX”.”SYS_EXPORT_TABLE_01″ successfully loaded/unloaded

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

Dump file set for ZX.SYS_EXPORT_TABLE_01 is:

  /home/oracle/e1_1.dmp

Job “ZX”.”SYS_EXPORT_TABLE_01″ successfully completed at Thu Jul 21 14:25:49 2016 elapsed 0 00:00:06

[oracle@rhel6 ~]$ exit

exit

测试复杂 query 导出

linuxidc@ORCL>select count(*) from e1 where id in(select id from e2 where birthday<sysdate);

  COUNT(*)

———-

31

[oracle@rhel6 ~]$ expdp zx/zx directory=dir dumpfile=e1_2.dmp tables=zx.e1 query=zx.e1:\”where id in \(select id from e2 where birthday\<sysdate\)\”

Export: Release 11.2.0.4.0 – Production on Thu Jul 21 14:31:04 2016

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, OLAP, Data Mining and Real Application Testing options

Starting “ZX”.”SYS_EXPORT_TABLE_01″:  zx/******** directory=dir dumpfile=e1_2.dmp tables=zx.e1 query=zx.e1:”where id in (select id from e2 where birthday<sysdate)”

Estimate in progress using BLOCKS method…

Processing object type TABLE_EXPORT/TABLE/TABLE_DATA

Total estimation using BLOCKS method: 64 KB

Processing object type TABLE_EXPORT/TABLE/TABLE

. . exported “ZX”.”E1″                                  6.242 KB      31 rows

Master table “ZX”.”SYS_EXPORT_TABLE_01″ successfully loaded/unloaded

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

Dump file set for ZX.SYS_EXPORT_TABLE_01 is:

  /home/oracle/e1_2.dmp

Job “ZX”.”SYS_EXPORT_TABLE_01″ successfully completed at Thu Jul 21 14:31:12 2016 elapsed 0 00:00:06

[oracle@rhel6 ~]$ exit

exit

linuxidc@ORCL>host

测试复杂 query 及 flashback_scn 导出

[oracle@rhel6 ~]$ expdp zx/zx directory=dir dumpfile=e1_3.dmp tables=zx.e1 query=zx.e1:\”where id in \(select id from e2 where birthday\<sysdate\)\”  flashback_scn=2179047

Export: Release 11.2.0.4.0 – Production on Thu Jul 21 14:32:07 2016

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, OLAP, Data Mining and Real Application Testing options

Starting “ZX”.”SYS_EXPORT_TABLE_01″:  zx/******** directory=dir dumpfile=e1_3.dmp tables=zx.e1 query=zx.e1:”where id in (select id from e2 where birthday<sysdate)” flashback_scn=2179047

Estimate in progress using BLOCKS method…

Processing object type TABLE_EXPORT/TABLE/TABLE_DATA

Total estimation using BLOCKS method: 64 KB

Processing object type TABLE_EXPORT/TABLE/TABLE

. . exported “ZX”.”E1″                                  6.757 KB      50 rows

Master table “ZX”.”SYS_EXPORT_TABLE_01″ successfully loaded/unloaded

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

Dump file set for ZX.SYS_EXPORT_TABLE_01 is:

  /home/oracle/e1_3.dmp

Job “ZX”.”SYS_EXPORT_TABLE_01″ successfully completed at Thu Jul 21 14:32:14 2016 elapsed 0 00:00:06

[oracle@rhel6 ~]$ exit

exit

删除 e2 部分数据

linuxidc@ORCL>delete from e2 where id>25 and id<30;

4 rows deleted.

linuxidc@ORCL>commit;

Commit complete.

linuxidc@ORCL>select count(*) from e1 where id in(select id from e2 where birthday<sysdate);

  COUNT(*)

———-

27

测试 query 及 flashback_scn,结果只是对 e1 应用 flashback_snc,e2 没有应用

linuxidc@ORCL>host

[oracle@rhel6 ~]$ expdp zx/zx directory=dir dumpfile=e1_4.dmp tables=zx.e1 query=zx.e1:\”where id in \(select id from e2 where birthday\<sysdate\)\”  flashback_scn=2179047

Export: Release 11.2.0.4.0 – Production on Thu Jul 21 14:33:55 2016

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, OLAP, Data Mining and Real Application Testing options

Starting “ZX”.”SYS_EXPORT_TABLE_01″:  zx/******** directory=dir dumpfile=e1_4.dmp tables=zx.e1 query=zx.e1:”where id in (select id from e2 where birthday<sysdate)” flashback_scn=2179047

Estimate in progress using BLOCKS method…

Processing object type TABLE_EXPORT/TABLE/TABLE_DATA

Total estimation using BLOCKS method: 64 KB

Processing object type TABLE_EXPORT/TABLE/TABLE

. . exported “ZX”.”E1″                                  6.648 KB      46 rows

Master table “ZX”.”SYS_EXPORT_TABLE_01″ successfully loaded/unloaded

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

Dump file set for ZX.SYS_EXPORT_TABLE_01 is:

  /home/oracle/e1_4.dmp

Job “ZX”.”SYS_EXPORT_TABLE_01″ successfully completed at Thu Jul 21 14:34:03 2016 elapsed 0 00:00:06

[oracle@rhel6 ~]$ exit

exit

使 e1 和 e2 都应用 flashback_scn

linuxidc@ORCL>select count(*) from e1 where id in(select id from e2 as of scn 2179047 where birthday<sysdate);

  COUNT(*)

———-

31

linuxidc@ORCL>host

[oracle@rhel6 ~]$ expdp zx/zx directory=dir dumpfile=e1_5.dmp tables=zx.e1 query=zx.e1:\”where id in \(select id from e2  as of scn 2179047  where birthday\<sysdate\)\”  flashback_scn=2179047

Export: Release 11.2.0.4.0 – Production on Thu Jul 21 14:39:52 2016

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, OLAP, Data Mining and Real Application Testing options

Starting “ZX”.”SYS_EXPORT_TABLE_01″:  zx/******** directory=dir dumpfile=e1_5.dmp tables=zx.e1 query=zx.e1:”where id in (select id from e2 as of scn2179047 where birthday<sysdate)” flashback_scn=2179047

Estimate in progress using BLOCKS method…

Processing object type TABLE_EXPORT/TABLE/TABLE_DATA

Total estimation using BLOCKS method: 64 KB

Processing object type TABLE_EXPORT/TABLE/TABLE

. . exported “ZX”.”E1″                                  6.757 KB      50 rows

Master table “ZX”.”SYS_EXPORT_TABLE_01″ successfully loaded/unloaded

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

多个表使用 query 条件则使用 ’,’ 分开

[oracle@rhel6 ~]$ expdp system/123456 directory=dump dumpfile=query.dmp tables=zx.abc,zx.abce query=zx.abc:\”where id \< 4\”,zx.abce:\”where id \< 4\”

Export: Release 11.2.0.4.0 – Production on Fri Dec 9 16:13:41 2016

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, OLAP, Data Mining and Real Application Testing options

FLASHBACK automatically enabled to preserve database integrity.

Starting “SYSTEM”.”SYS_EXPORT_TABLE_01″:  system/******** directory=dump dumpfile=query.dmp tables=zx.abc,zx.abce query=zx.abc:”where id < 4″,zx.abce:”where id < 4″

Estimate in progress using BLOCKS method…

Processing object type TABLE_EXPORT/TABLE/TABLE_DATA

Total estimation using BLOCKS method: 384 KB

Processing object type TABLE_EXPORT/TABLE/TABLE

. . exported “ZX”.”ABC”                                  5.898 KB      2 rows

. . exported “ZX”.”ABCE”                                5.898 KB      2 rows

Master table “SYSTEM”.”SYS_EXPORT_TABLE_01″ successfully loaded/unloaded

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

Dump file set for SYSTEM.SYS_EXPORT_TABLE_01 is:

  /home/oracle/query.dmp

Job “SYSTEM”.”SYS_EXPORT_TABLE_01″ successfully completed at Fri Dec 9 16:14:04 2016 elapsed 0 00:00:19

更多 Oracle 相关信息见 Oracle 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=12

本文永久更新链接地址 :http://www.linuxidc.com/Linux/2016-12/138213.htm

正文完
星哥玩云-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2022-01-22发表,共计9600字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中

星哥玩云

星哥玩云
星哥玩云
分享互联网知识
用户数
4
文章数
19348
评论数
4
阅读量
7801328
文章搜索
热门文章
开发者必备神器:阿里云 Qoder CLI 全面解析与上手指南

开发者必备神器:阿里云 Qoder CLI 全面解析与上手指南

开发者必备神器:阿里云 Qoder CLI 全面解析与上手指南 大家好,我是星哥。之前介绍了腾讯云的 Code...
星哥带你玩飞牛NAS-6:抖音视频同步工具,视频下载自动下载保存

星哥带你玩飞牛NAS-6:抖音视频同步工具,视频下载自动下载保存

星哥带你玩飞牛 NAS-6:抖音视频同步工具,视频下载自动下载保存 前言 各位玩 NAS 的朋友好,我是星哥!...
云服务器部署服务器面板1Panel:小白轻松构建Web服务与面板加固指南

云服务器部署服务器面板1Panel:小白轻松构建Web服务与面板加固指南

云服务器部署服务器面板 1Panel:小白轻松构建 Web 服务与面板加固指南 哈喽,我是星哥,经常有人问我不...
我把用了20年的360安全卫士卸载了

我把用了20年的360安全卫士卸载了

我把用了 20 年的 360 安全卫士卸载了 是的,正如标题你看到的。 原因 偷摸安装自家的软件 莫名其妙安装...
星哥带你玩飞牛NAS-3:安装飞牛NAS后的很有必要的操作

星哥带你玩飞牛NAS-3:安装飞牛NAS后的很有必要的操作

星哥带你玩飞牛 NAS-3:安装飞牛 NAS 后的很有必要的操作 前言 如果你已经有了飞牛 NAS 系统,之前...
阿里云CDN
阿里云CDN-提高用户访问的响应速度和成功率
随机文章
仅2MB大小!开源硬件监控工具:Win11 无缝适配,CPU、GPU、网速全维度掌控

仅2MB大小!开源硬件监控工具:Win11 无缝适配,CPU、GPU、网速全维度掌控

还在忍受动辄数百兆的“全家桶”监控软件?后台偷占资源、界面杂乱冗余,想查个 CPU 温度都要层层点选? 今天给...
在Windows系统中通过VMware安装苹果macOS15

在Windows系统中通过VMware安装苹果macOS15

在 Windows 系统中通过 VMware 安装苹果 macOS15 许多开发者和爱好者希望在 Window...
Prometheus:监控系统的部署与指标收集

Prometheus:监控系统的部署与指标收集

Prometheus:监控系统的部署与指标收集 在云原生体系中,Prometheus 已成为最主流的监控与报警...
星哥带你玩飞牛NAS-6:抖音视频同步工具,视频下载自动下载保存

星哥带你玩飞牛NAS-6:抖音视频同步工具,视频下载自动下载保存

星哥带你玩飞牛 NAS-6:抖音视频同步工具,视频下载自动下载保存 前言 各位玩 NAS 的朋友好,我是星哥!...
如何免费使用强大的Nano Banana Pro?附赠邪修的用法

如何免费使用强大的Nano Banana Pro?附赠邪修的用法

如何免费使用强大的 Nano Banana Pro?附赠邪修的用法 前言 大家好,我是星哥,今天来介绍谷歌的 ...

免费图片视频管理工具让灵感库告别混乱

一言一句话
-「
手气不错
星哥带你玩飞牛NAS-14:解锁公网自由!Lucky功能工具安装使用保姆级教程

星哥带你玩飞牛NAS-14:解锁公网自由!Lucky功能工具安装使用保姆级教程

星哥带你玩飞牛 NAS-14:解锁公网自由!Lucky 功能工具安装使用保姆级教程 作为 NAS 玩家,咱们最...
安装Black群晖DSM7.2系统安装教程(在Vmware虚拟机中、实体机均可)!

安装Black群晖DSM7.2系统安装教程(在Vmware虚拟机中、实体机均可)!

安装 Black 群晖 DSM7.2 系统安装教程(在 Vmware 虚拟机中、实体机均可)! 前言 大家好,...
还在找免费服务器?无广告免费主机,新手也能轻松上手!

还在找免费服务器?无广告免费主机,新手也能轻松上手!

还在找免费服务器?无广告免费主机,新手也能轻松上手! 前言 对于个人开发者、建站新手或是想搭建测试站点的从业者...
手把手教你,购买云服务器并且安装宝塔面板

手把手教你,购买云服务器并且安装宝塔面板

手把手教你,购买云服务器并且安装宝塔面板 前言 大家好,我是星哥。星哥发现很多新手刚接触服务器时,都会被“选购...
安装并使用谷歌AI编程工具Antigravity(亲测有效)

安装并使用谷歌AI编程工具Antigravity(亲测有效)

  安装并使用谷歌 AI 编程工具 Antigravity(亲测有效) 引言 Antigravity...