exp按条件导出的研究query

--从生产导数据时发现ods库不能用expdp,于是想试一下exp方法
--但发现也不行。不过研究了一下exp的条件导出语句

--exp不同于expdp,相对来说功能没expdp强大
--对于条件导出,exp相比expdp,不能进行多表多条件的导出,只能进行单个条件的限制
--实例语句:
exp scott/tiger TABLES=(emp,bonus) QUERY=\"WHEREjob=\'SALESMAN\' and sal\<1600\"

--推荐使用parfile文件进行exp导出,在parfile文件中query可以直接写成
QUERY="WHERE job='SALESMAN' andsal<1600" 
--而不需要进行字符的转义

--另外exp的条件导出有一些限制:
1.The parameter QUERY cannot be specified for full, user, ortablespace mode exports. 
参数query不能使用在完全导出,用户导出和表空间导出方式

2.The parameter QUERY must be applicable to all specifiedtables. 
参数query指定的内容必须对所有指定的表都有效

3.The parameter QUERY cannot be specified in a direct pathexport (DIRECT=y) 
参数query不能与direct路径导出同时使用,因为direct是直接路径读取数据文件导出,而使用了条件语句就必须走sql方法导出了
所以不能同时使用

4.The parameter QUERY cannot be specified for tables withinner nested tables. 
参数query不能导出内嵌表

5.You cannot determine from the contents of the export filewhether the data is the result of a QUERYexport. 
用query参数导出的数据与同其他方式导出的数据是一样的,无法根据导出文件进行分辨



--实验
--实验环境:本地linux虚拟机,Oracle数据库版本11gR2

--创建相关测试表
create table scott.exp_obj as select * from dba_objects;
create table scott.exp_tab as select * from dba_tables;


--1、exp条件导出
[oracle@localhost ~]$ cd /home/software
[oracle@localhost exp_dir]$ vi exp_test1.par
userid='/ as sysdba'
file=exp_test1.dmp
tables=(scott.exp_obj,scott.exp_tab)
query="where owner='SCOTT'"
log=exp_test1.log
[oracle@localhost exp_dir]$exp parfile=exp_test1.par

--结果:成功导出部分数据
About to export specified tables via Conventional Path...
Current user changed to SCOTT
. . exporting table                         EXP_OBJ         19 rows exported
. . exporting table                         EXP_TAB           8 rowsexported
Export terminated successfully without warnings.


--2、exp条件不是对所有表都适用的情况
[oracle@localhost exp_dir]$ vi exp_test2.par
userid='/ as sysdba'
file=exp_test2.dmp
tables=(scott.exp_obj,scott.exp_tab)
query="where owner='SCOTT' and table_name is not null"
log=exp_test2.log
[oracle@localhost exp_dir]$exp parfile=exp_test2.par

--结果:不适用约束的表导出报错,适用约束的表导出成功
About to export specified tables via Conventional Path...
Current user changed to SCOTT
. . exporting table                         EXP_OBJ
EXP-00056: ORACLE error 904 encountered
ORA-00904: "TABLE_NAME": invalid identifier
. . exporting table                         EXP_TAB           8 rowsexported
Export terminated successfully with warnings.


--3、exp条件导出与direct路径同时使用
[oracle@localhost ~]$ cd /home/software
[oracle@localhost exp_dir]$ vi exp_test3.par
userid='/ as sysdba'
file=exp_test3.dmp
tables=(scott.exp_obj,scott.exp_tab)
query="where owner='SCOTT'"
direct=y
log=exp_test3.log
[oracle@localhost exp_dir]$exp parfile=exp_test3.par

--结果:报错,导出失败,无法query导出和direct路径同时使用
Connected to: Oracle Database 11g Enterprise Edition Release11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real ApplicationTesting options
EXP-00071: QUERY parameter not compatible with Direct Pathexport
EXP-00000: Export terminated unsuccessfully





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值