expdp query及parfile的使用

     在使用expdp导出数据时,我们可以使用query参数指定导出表的部分数据,query参数可以直接在expdp命令行中使用,也可以在parfile文件中使用

一:在命令行中使用query

1.执行命令

export ORACLE_SID=XXXXX
expdp \'sys/********* as sysdba\' directory=sfdir dumpfile=test.dmp logfile=test.log tables=scott.test1,scott.test2 query=scott.test1:\"where UA_SERIAL_ID in \(\'96\',\'26\'\)\",scott.test2:\"where FILESIZE=273899\"

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Export: Release 11.2.0.3.0 - Production on Wed Jun 3 11:22:30 2015

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, Real Application Clusters, OLAP, Data Mining
and Real Application Testing options
Starting "SYS"."SYS_EXPORT_TABLE_01":  "sys/******** AS SYSDBA" directory=sfdir dumpfile=test.dmp logfile=test.log tables=scott.test1,scott.test2 query=scott.test1:"where UA_SERIAL_ID in ('96','26')",scott.test2:"where FILESIZE=273899" 
Estimate in progress using BLOCKS method...
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 2.25 GB
Processing object type TABLE_EXPORT/TABLE/TABLE
. . exported "SCOTT"."TEST1"                             172.5 MB 1834060 rows
. . exported "SCOTT"."TEST2"                             27.87 KB     186 rows
Master table "SYS"."SYS_EXPORT_TABLE_01" successfully loaded/unloaded
******************************************************************************
Dump file set for SYS.SYS_EXPORT_TABLE_01 is:
  /archlog/egcmc_exp/test.dmp
Job "SYS"."SYS_EXPORT_TABLE_01" successfully completed at 11:22:57
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
##注意query选项后面的内容,很多符号需要使用转译符号“\”才能保证备份命令的正常运行,如上面()括号,以及‘’单引号,""双引号都需要使用转译符进行转译

2.验证导出结果

SQL> select count(1) from scott.test1 where UA_SERIAL_ID in ('96','26');

  COUNT(1)
----------
   1834060

SQL> select count(1) from scott.test1 where FILESIZE=273899;

  COUNT(1)
----------
       186
##导出结果正确

二:expdp 使用parfile导出

##如果需要导出多个表的部分数据,那么如果用命令方式写,因为需要转译,是很麻烦的,也容易出错,这时我们可以使用parfile文件来避免大量的转译

1.首先看一下我们parfile.txt文件中的内容

cat parfile.txt(parfile可以随意命名)
tables=
(
 CHANNEL.TR_CHANNEL_ACCESS_LOG_BAK,
 scott.test1,
 scott.test2
)
query=
(
 xxxxx.TR_XXXX_ACCESS_LOG_BAK:"where CHANNEL_CODE='10689021144'",
 scott.test1:"where UA_SERIAL_ID in ('96','26')",
 scott.test2:"where FILESIZE=273899"
)
##注意 :"冒号前无空格。表名不能重复使用,表不能有别名

##如果parfile中tables或者query中表名有重复会报如下错误:

ORA-39001: invalid argument value
ORA-39035: Data filter SUBQUERY has already been specified.


2.执行expdp命令

export ORACLE_SID=XXXXX 
expdp \'sys/********* as sysdba\' directory=sfdir dumpfile=export.dmp logfile=export.log parfile=/archlog/parfile.txt

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Export: Release 11.2.0.3.0 - Production on Wed Jun 3 11:27:18 2015

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, Real Application Clusters, OLAP, Data Mining
and Real Application Testing options
Starting "SYS"."SYS_EXPORT_TABLE_01":  "sys/******** AS SYSDBA" directory=sfdir dumpfile=export.dmp logfile=export.log parfile=/archlog/parfile.txt 
Estimate in progress using BLOCKS method...
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 9.982 GB
Processing object type TABLE_EXPORT/TABLE/TABLE
Processing object type TABLE_EXPORT/TABLE/INDEX/INDEX
Processing object type TABLE_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
Processing object type TABLE_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
. . exported "XXXXX"."TR_xxxx_ACCESS_LOG_BAK":"ACCESS_LOG_PART11"  8.804 KB       0 rows
. . exported "XXXXX"."TR_xxxx_ACCESS_LOG_BAK":"ACCESS_LOG_PART12"  11.83 KB       8 rows
. . exported "XXXXX"."TR_xxxx_ACCESS_LOG_BAK":"ACCESS_LOG_PART10"  8.804 KB       0 rows
. . exported "SCOTT"."TEST1"                             172.5 MB 1834060 rows
. . exported "SCOTT"."TEST2"                             27.87 KB     186 rows
. . exported "XXXXX"."TR_xxxx_ACCESS_LOG_BAK":"ACCESS_LOG_PART13"  10.68 KB       5 rows
. . exported "XXXXX"."TR_xxxx_ACCESS_LOG_BAK":"ACCESS_LOG_PART14"  8.804 KB       0 rows
. . exported "XXXXX"."TR_xxxx_ACCESS_LOG_BAK":"ACCESS_LOG_PART15"  9.187 KB       1 rows
. . exported "XXXXX"."TR_xxxx_ACCESS_LOG_BAK":"ACCESS_LOG_PART16"  8.804 KB       0 rows
. . exported "XXXXX"."TR_xxxx_ACCESS_LOG_BAK":"ACCESS_LOG_PART17"  9.187 KB       1 rows
. . exported "XXXXX"."TR_xxxx_ACCESS_LOG_BAK":"ACCESS_LOG_PART18"  8.804 KB       0 rows
. . exported "XXXXX"."TR_xxxx_ACCESS_LOG_BAK":"ACCESS_LOG_PART1"      0 KB       0 rows
. . exported "XXXXX"."TR_xxxx_ACCESS_LOG_BAK":"ACCESS_LOG_PART2"      0 KB       0 rows
. . exported "XXXXX"."TR_xxxx_ACCESS_LOG_BAK":"ACCESS_LOG_PART3"      0 KB       0 rows
. . exported "XXXXX"."TR_xxxx_ACCESS_LOG_BAK":"ACCESS_LOG_PART4"      0 KB       0 rows
. . exported "XXXXX"."TR_xxxx_ACCESS_LOG_BAK":"ACCESS_LOG_PART5"      0 KB       0 rows
. . exported "XXXXX"."TR_xxxx_ACCESS_LOG_BAK":"ACCESS_LOG_PART6"      0 KB       0 rows
. . exported "XXXXX"."TR_xxxx_ACCESS_LOG_BAK":"ACCESS_LOG_PART7"      0 KB       0 rows
Master table "SYS"."SYS_EXPORT_TABLE_01" successfully loaded/unloaded
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------


##我们可以把expdp命令需要使用的参数都写进参数文件中,类似如下:

PARALLEL=3
cluster=no 
COMPRESSION=ALL
DUMPFILE=export_%U.dmp  
DIRECTORY=sfdir   
logfile=export.log
EXCLUDE=TRIGGER,INDEX,STATISTICS
tables=
(
 xxxxx.TR_xxxx_ACCESS_LOG_BAK,
 scott.test1,
 scott.test2
)
query=
(
 xxxxx.TR_xxxx_ACCESS_LOG_BAK:"where CHANNEL_CODE='10689021144'",
 scott.test1:"where UA_SERIAL_ID in ('96','26')",
 scott.test2:"where FILESIZE=273899"
)

然后执行如下命令

export ORACLE_SID=XXXXX
expdp \'sys/*********** as sysdba\' parfile=/archlog/parfile.txt


  • 1
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

渔夫数据库笔记

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值