Oracle 11g expdp中query参数的使用
admin
2023-04-30 01:40:06
0

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

数据库版本

zx@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

创建测试表

zx@ORCL>create table e1 (id number,name varchar2(20));
Table created.
zx@ORCL>create table e2 (id number,birthday date);
Table created.

插入测试数据

zx@ORCL>insert into e1 select level,lpad(level,20,'*') from dual connect by level <= 100;
100 rows created.
zx@ORCL>commit;
Commit complete.
zx@ORCL>insert into e2 select level,sysdate-50+level from dual connect by level <= 100;
100 rows created.
zx@ORCL>commit;
Commit complete.

创建目录

zx@ORCL>create directory dir as '/home/oracle/';
Directory created.
zx@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号

zx@ORCL>select dbms_flashback.get_system_change_number from dual;
GET_SYSTEM_CHANGE_NUMBER
------------------------
 2179047
zx@ORCL>select count(*) from e1;
  COUNT(*)
----------
       100

删除部分数据

zx@ORCL>delete from e1 where id<20;
19 rows deleted.
zx@ORCL>commit;
Commit complete.
zx@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导出

zx@ORCL>select count(*) from e1 where id in( select id from e2 where birthdayhost

测试复杂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\

删除e2部分数据

zx@ORCL>delete from e2 where id>25 and id<30;
4 rows deleted.
zx@ORCL>commit;
Commit complete.
zx@ORCL>select count(*) from e1 where id in( select id from e2 where birthday

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

zx@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\

使e1和e2都应用flashback_scn

zx@ORCL>select count(*) from e1 where id in( select id from e2 as of scn 2179047 where birthdayhost
[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\

多个表使用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


相关内容

热门资讯

国台办:买再多的武器都是螳臂当... 5月13日,国务院台办举行例行新闻发布会。总台记者就台湾军购费用引发舆论质疑提问。发言人张晗表示,我...
豫篮联赛:赛场劲吹“文旅风” 汉服小姐姐在看台上翩翩起舞。胡斌 摄洛阳队球员上篮。胡斌 摄“五一”小长假后,豫篮联赛伴随着初夏的热...
凡星闪耀丨《武林外传》中小米扮... 张清(右)在免费餐厅为大家服务。张清在《武林外传》中饰演“丐帮弟子”小米(右)。在郑州的城市烟火气中...
卫华:做走向世界的“起重管家” 卫华集团智能生产车间。常晶晶 摄作为全省服务业大会的参会企业,河南卫华重型机械股份有限公司(以下简称...
在加快国际消费中心城市建设中彰... “服务业是推动经济高质量发展的重要引擎,也是强化国家中心城市核心竞争力的重要支柱。”5月12日,省委...
坚定不移沿着习近平总书记指引的... 壮美的郑州黄河文化公园。河南日报资料图片 河南日报全媒体记者 聂冬晗 摄来郑州,到哪里慢赏大河风光?...
双庆同辉映初心——黄河科技学院... 2026年5月12日,黄河科技学院附属医院迎来开诊七周年纪念日,恰逢第115个国际护士节。当天,医院...
驻美大使谢锋回应中美热点问题 据中国驻美国大使馆5月13日消息,5月5日,中国驻美国大使谢锋就美国总统特朗普访华和中美关系接受美国...
邻妹妹帮办 | 占地1.2万㎡... “杞县有个婚礼庄园,6 大主题特色宴会厅,可同时容纳2000人聚餐,在未变更工业用地用途、未经消防验...
国台办:和平统一后,台湾同胞民... 5月13日,国务院台办举行例行新闻发布会。有记者问,国务院台办发言人在之前发布会上已分别阐释了和平统...