【PARFILE】使用exp或expdp的PARFILE参数避免QUERY内容的繁琐转义问题

  使用exp或者expdp工具的parfile参数可以有效的避免query参数书写时在不同操作系统平台的特殊字符进行转移的发生。尽量减少出错的几率,节省备份任务的完成的时间。

  关于exp和expdp工具的query参数的使用方法请参见如下文章。
  《【EXP】使用EXP的QUERY选项导出表中部分数据》(http://space.itpub.net/519536/viewspace-628841)
  《【EXPDP】使用expdp的QUERY参数限定备份数据的范围》(http://space.itpub.net/519536/viewspace-558297)

  本文给出exp和expdp工具的parfile参数的使用方法。

1.环境准备
1)创建测试用表T
sec@ora10g> create table t (x varchar2(10));

Table created.

2)初始化数据
sec@ora10g> insert into t values ('secooler');
sec@ora10g> insert into t values ('secooler');
sec@ora10g> insert into t values ('HOU');
sec@ora10g> insert into t values ('HOU');
sec@ora10g> insert into t values ('Good luck!');
sec@ora10g> insert into t values ('Good luck!');
sec@ora10g> commit;

Commit complete.

sec@ora10g> select * from t;

X
----------
secooler
secooler
HOU
HOU
Good luck!
Good luck!

6 rows selected.

2.不使用参数文件的exp和expdp数据导出
这里给出使用exp和expdp命令备份t表中x字段等于“secooler”的记录。操作系统平台为Linux。
1)exp工具直接备份
ora10g@secdb /db_backup/dpump_dir$ exp sec/sec file=t.dmp log=t.log tables=t query=\"where x=\'secooler\'\"

Export: Release 10.2.0.1.0 - Production on Thu May 5 21:18:08 2011

Copyright (c) 1982, 2005, Oracle.  All rights reserved.


Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
Export done in US7ASCII character set and AL16UTF16 NCHAR character set
server uses WE8ISO8859P1 character set (possible charset conversion)

About to export specified tables via Conventional Path ...
. . exporting table                              T          2 rows exported
Export terminated successfully without warnings.

2)expdp直接备份
ora10g@secdb /db_backup/dpump_dir$ expdp sec/sec directory=dpump_dir dumpfile=t.dmp logfile=t.log tables=t query=\"where x=\'secooler\'\"

Export: Release 10.2.0.1.0 - Production on Thursday, 05 May, 2011 21:20:38

Copyright (c) 2003, 2005, Oracle.  All rights reserved.

Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
Starting "SEC"."SYS_EXPORT_TABLE_01":  sec/******** directory=dpump_dir dumpfile=t.dmp logfile=t.log tables=t query="where x='secooler'"
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 "SEC"."T"                                   4.937 KB       2 rows
Master table "SEC"."SYS_EXPORT_TABLE_01" successfully loaded/unloaded
******************************************************************************
Dump file set for SEC.SYS_EXPORT_TABLE_01 is:
  /db_backup/dpump_dir/t.dmp
Job "SEC"."SYS_EXPORT_TABLE_01" successfully completed at 21:20:51

注意query选项后面的内容,需要使用很多转移符号“\”才能保证备份命令的正常运行,当限定条件众多时非常容易出现修改不全的问题,从而浪费大量的时间。

3.使用参数文件的exp和expdp数据导出
1)参数文件准备
ora10g@secdb /db_backup/dpump_dir$ vi t.par
query="where x = 'secooler'"

~
~

命令行中繁琐的转义问题在这里得到了有效的解决。在双引号之间可以尽情写入where子句内容!

2)exp使用参数文件备份
ora10g@secdb /db_backup/dpump_dir$ exp sec/sec file=t.dmp log=t.log tables=t parfile=t.par

Export: Release 10.2.0.1.0 - Production on Thu May 5 21:45:35 2011

Copyright (c) 1982, 2005, Oracle.  All rights reserved.


Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
Export done in US7ASCII character set and AL16UTF16 NCHAR character set
server uses WE8ISO8859P1 character set (possible charset conversion)

About to export specified tables via Conventional Path ...
. . exporting table                              T          2 rows exported
EXP-00091: Exporting questionable statistics.
Export terminated successfully with warnings.

3)expdp使用参数文件备份
ora10g@secdb /db_backup/dpump_dir$ expdp sec/sec directory=dpump_dir dumpfile=t.dmp logfile=t.log tables=t parfile=t.par

Export: Release 10.2.0.1.0 - Production on Thursday, 05 May, 2011 22:04:36

Copyright (c) 2003, 2005, Oracle.  All rights reserved.

Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
Starting "SEC"."SYS_EXPORT_TABLE_01":  sec/******** directory=dpump_dir dumpfile=t.dmp logfile=t.log tables=t parfile=t.par
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
Processing object type TABLE_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
. . exported "SEC"."T"                                   4.937 KB       2 rows
Master table "SEC"."SYS_EXPORT_TABLE_01" successfully loaded/unloaded
******************************************************************************
Dump file set for SEC.SYS_EXPORT_TABLE_01 is:
  /db_backup/dpump_dir/t.dmp
Job "SEC"."SYS_EXPORT_TABLE_01" successfully completed at 22:04:50

exp和expdp命令均能顺利有效的执行。

4.小结
  QUERY内容繁琐转义的烦恼到此得到了一个完美的处理。这个小小的变化可以节省大量宝贵时间。建议在使用query参数时尽量结合parfile参数文件方法来处理。

Good luck.

secooler
11.05.05

-- The End --

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/519536/viewspace-694577/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/519536/viewspace-694577/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值