ITPub博客

首页 > 数据库 > Oracle > ORACLE 使用EXPDP按条件导出

ORACLE 使用EXPDP按条件导出

原创 Oracle 作者:邪丶坏人 时间:2017-03-23 14:42:36 0 删除 编辑
就拿EMP表当例子
案例1:要求把deptno=20的数据导出来
语句:
expdp scott/oracle directory=xx dumpfile=2emp.dmp tables=emp query='emp:"WHERE deptno=20"';  ---注意后面这几个"'是"+'

点击(此处)折叠或打开

  1. [oracle@xie xie]$ expdp scott/oracle directory=xx dumpfile=2emp.dmp tables=emp query='emp:"WHERE deptno=20"';
  2. Export: Release 11.2.0.4.0 - Production on Thu Mar 23 14:24:32 2017
  3. Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
  4. Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
  5. With the Partitioning, OLAP, Data Mining and Real Application Testing options
  6. Starting "SCOTT"."SYS_EXPORT_TABLE_01": scott/******** directory=xx dumpfile=2emp.dmp tables=emp query=emp:"WHERE deptno=20"
  7. Estimate in progress using BLOCKS method...
  8. Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
  9. Total estimation using BLOCKS method: 64 KB
  10. Processing object type TABLE_EXPORT/TABLE/TABLE
  11. Processing object type TABLE_EXPORT/TABLE/INDEX/INDEX
  12. Processing object type TABLE_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
  13. Processing object type TABLE_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
  14. Processing object type TABLE_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINT
  15. Processing object type TABLE_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
  16. . . exported "SCOTT"."EMP" 8.195 KB 5 rows
  17. Master table "SCOTT"."SYS_EXPORT_TABLE_01" successfully loaded/unloaded
  18. ******************************************************************************
  19. Dump file set for SCOTT.SYS_EXPORT_TABLE_01 is:
  20.   /xie/2emp.dmp
  21. Job "SCOTT"."SYS_EXPORT_TABLE_01" successfully completed at Thu Mar 23 14:24:38 2017 elapsed 0 00:00:06
然后如果要把这些数据导入到emp表里的话,先去删除原表的这几条数据,再去执行以下语句导入:
impdp scott/oracle dumpfile=2emp.dmp directory=xx content=data_only  

点击(此处)折叠或打开

  1. [oracle@xie xie]$ impdp scott/oracle dumpfile=2emp.dmp directory=xx content=data_only 
  2. Import: Release 11.2.0.4.0 - Production on Thu Mar 23 14:25:59 2017
  3. Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
  4. Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
  5. With the Partitioning, OLAP, Data Mining and Real Application Testing options
  6. Master table "SCOTT"."SYS_IMPORT_FULL_01" successfully loaded/unloaded
  7. Starting "SCOTT"."SYS_IMPORT_FULL_01": scott/******** dumpfile=2emp.dmp directory=xx content=data_only
  8. Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
  9. . . imported "SCOTT"."EMP" 8.195 KB 5 rows
  10. Job "SCOTT"."SYS_IMPORT_FULL_01" successfully completed at Thu Mar 23 14:26:03 2017 elapsed 0 00:00:03


案例2:要求把ename='KING'的这条数据导出来
如果query里的条件是字符串的话,就要用下面这种方法:
先写出一个参数文件txt.par

[oracle@xie xie]$ cat txt.par 
dumpfile=1emp.dmp
directory=xx
tables=(emp)
query=(emp:"where ename='KING'")
然后执行导出语句:
expdp scott/oracle parfile=txt.par

点击(此处)折叠或打开

  1. [oracle@xie xie]$ expdp scott/oracle parfile=txt.par 
  2. Export: Release 11.2.0.4.0 - Production on Thu Mar 23 14:12:13 2017
  3. Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
  4. Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
  5. With the Partitioning, OLAP, Data Mining and Real Application Testing options
  6. Starting "SCOTT"."SYS_EXPORT_TABLE_01": scott/******** parfile=txt.par
  7. Estimate in progress using BLOCKS method...
  8. Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
  9. Total estimation using BLOCKS method: 64 KB
  10. Processing object type TABLE_EXPORT/TABLE/TABLE
  11. Processing object type TABLE_EXPORT/TABLE/INDEX/INDEX
  12. Processing object type TABLE_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
  13. Processing object type TABLE_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
  14. Processing object type TABLE_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINT
  15. Processing object type TABLE_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
  16. . . exported "SCOTT"."EMP" 8.031 KB 1 rows
  17. Master table "SCOTT"."SYS_EXPORT_TABLE_01" successfully loaded/unloaded
  18. ******************************************************************************
  19. Dump file set for SCOTT.SYS_EXPORT_TABLE_01 is:
  20.   /xie/1emp.dmp
  21. Job "SCOTT"."SYS_EXPORT_TABLE_01" successfully completed at Thu Mar 23 14:12:21 2017 elapsed 0 00:00:07
导入方法和案例1的一样

注:如果query里的条件是字符串还用案例1的方法,就会报错
ORA-31693: Table data object "SCOTT"."EMP" failed to load/unload and is being skipped due to error:
ORA-00904: "KING": invalid identifier
还在探索这个错误的原因,待研究


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

请登录后发表评论 登录
全部评论
多年的DBA从业经验,有扎实的linux和Oracle运维和故障处理的能力; 对oracle rac,adg,ogg,rman备份恢复,异机恢复,分区表,数据迁移,sql优化,版本升级,数据库架构设计,故障处理都较为熟练

注册时间:2016-04-01

  • 博文量
    53
  • 访问量
    124327