技术头条 - 一个快速在微博传播文章的方式     搜索本站
您现在的位置首页 --> Oracle --> ORACLE 12C可以通过expdp导出view数据

ORACLE 12C可以通过expdp导出view数据

浏览:3874次  出处信息

有时候,多么的希望ORACLE能够导出某个视图中的数据,然后通过这个视图来迁移需要的数据,现在ORACLE 12C通过expdp的views_as_tables来实现了该功能,把视图当作一个普通表从而导出数据,导入的时候直接和一个正常表一样,通过视图的导出,表的导入来实现相关需求
准备测试环境

SQL> SELECT* FROMV$VERSION;
 
BANNER                                                                               CON_ID
-------------------------------------------------------------------------------- ----------
Oracle Database12c Enterprise Edition Release 12.1.0.0.2 - 64bit Beta                    0
PL/SQL Release 12.1.0.0.2 - Beta                                                          0
CORE    12.1.0.0.2      Beta                                                              0
TNS forLinux: Version 12.1.0.0.2 - Beta                                                  0
NLSRTL Version 12.1.0.0.2 - Beta                         
 
SQL> createtablet_lx asselect* fromv$log; 
 
Tablecreated.
 
SQL> createtablet_xl asselect* fromv$logfile;
 
Tablecreated.
 
SQL> createviewv_xifenfei  as
  2   SELECTthread#,
  3           a.sequence#,
  4           a.group#,
  5           TO_CHAR (first_change#, '9999999999999999') "SCN",
  6           a.status,
  7           MEMBER
  8      FROMt_lx a, t_xl b
  9     WHEREa.group# = B.GROUP#
 10  ORDERBYa.sequence# DESC;
 
Viewcreated.
 
SQL> col member fora50
SQL> setlines 134
SQL> select* fromv_xifenfei;
 
   THREAD#  SEQUENCE#     GROUP# SCN               STATUS           MEMBER
---------- ---------- ---------- ----------------- ---------------- -------------------------------------------
         1         30          3            391892 CURRENT          /u01/app/oracle/oradata/xifenfei/redo03.log
         1         29          2            377363 INACTIVE         /u01/app/oracle/oradata/xifenfei/redo02.log
         1         28          1            374892 INACTIVE         /u01/app/oracle/oradata/xifenfei/redo01.log

expdp结合VIEWS_AS_TABLES导出视图

[oracle@xifenfei ~]$ expdp xff/xifenfeiviews_as_tables=v_xifenfei directory=data_pump_dir dumpfile=xifenfei.dmp
 
Export: Release 12.1.0.0.2 - Beta on Sun Dec 16 07:56:48 2012
 
Copyright (c) 1982, 2012, Oracle and/orits affiliates.  All rights reserved.
 
Connected to: Oracle Database 12c Enterprise Edition Release 12.1.0.0.2 - 64bit Beta
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Starting "XFF"."SYS_EXPORT_TABLE_01":xff/******** views_as_tables=v_xifenfei directory=data_pump_dir
 dumpfile=xifenfei.dmp
Estimate inprogress using BLOCKS method...
Processing object typeTABLE_EXPORT/VIEWS_AS_TABLES/TABLE_DATA
Total estimation using BLOCKS method: 16 KB
Processing object typeTABLE_EXPORT/VIEWS_AS_TABLES/TABLE
. . exported "XFF"."V_XIFENFEI"                          7.390 KB       3 rows
Master table "XFF"."SYS_EXPORT_TABLE_01"successfully loaded/unloaded
******************************************************************************
Dump filesetforXFF.SYS_EXPORT_TABLE_01 is:
  /u01/app/oracle/admin/xifenfei/dpdump/xifenfei.dmp
Job "XFF"."SYS_EXPORT_TABLE_01"successfully completed at Sun Dec 16 07:58:17 2012 elapsed 0 00:00:56

impdp导入数据

[oracle@xifenfei ~]$ impdp xff/xifenfeiremap_table=v_xifenfei:v_xff directory=data_pump_dir dumpfile=xifenfei.dmp
 
Import: Release 12.1.0.0.2 - Beta on Sun Dec 16 08:06:06 2012
 
Copyright (c) 1982, 2012, Oracle and/orits affiliates.  All rights reserved.
 
Connected to: Oracle Database 12c Enterprise Edition Release 12.1.0.0.2 - 64bit Beta
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Master table "XFF"."SYS_IMPORT_FULL_01"successfully loaded/unloaded
Starting "XFF"."SYS_IMPORT_FULL_01":xff/******** remap_table=v_xifenfei:v_xff directory=data_pump_dir
 dumpfile=xifenfei.dmp
Processing object typeTABLE_EXPORT/VIEWS_AS_TABLES/TABLE
Processing object typeTABLE_EXPORT/VIEWS_AS_TABLES/TABLE_DATA
. . imported "XFF"."V_XFF"                               7.390 KB       3 rows
Job "XFF"."SYS_IMPORT_FULL_01"successfully completed at Sun Dec 16 08:06:20 2012 elapsed 0 00:00:10

验证数据

SQL> COL OBJECT_NAME FORA20
SQL> selectobject_type,object_name fromuser_objectS whereobject_name like'V_X%';
 
OBJECT_TYPE             OBJECT_NAME
----------------------- --------------------
VIEW                    V_XIFENFEI
TABLE                   V_XFF
 
SQL> col member fora50
SQL> setlines 134
SQL> select* fromv_XFF;
 
   THREAD#  SEQUENCE#     GROUP# SCN               STATUS           MEMBER
---------- ---------- ---------- ----------------- ---------------- --------------------------------------------
         1         30          3            391892 CURRENT          /u01/app/oracle/oradata/xifenfei/redo03.log
         1         29          2            377363 INACTIVE         /u01/app/oracle/oradata/xifenfei/redo02.log
         1         28          1            374892 INACTIVE         /u01/app/oracle/oradata/xifenfei/redo01.log

通过测试证明在12C中ORACLE的expdp/impdp可以实现导出视图数据,进入导入到[其他库]其他表中

建议继续学习:

  1. EXPDP:使用ESTIMATE_ONLY参数评估ESTIMATE性能    (阅读:1762)
  2. cursor_sharing参数对于expdp的性能影响    (阅读:1540)
  3. EXPDP 过程中的 SYS_XMLGEN 性能影响    (阅读:1529)
QQ技术交流群:445447336,欢迎加入!
扫一扫订阅我的微信号:IT技术博客大学习
© 2009 - 2024 by blogread.cn 微博:@IT技术博客大学习

京ICP备15002552号-1