Oracle 12c 新特性 --- Oracle Data Pump Export View As a Table

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/leo__1990/article/details/90199330

概念

There is a new expdp command-line option for Oracle Data Pump Export that allows the user to indicate that a view should be exported as a table. This means that, instead of exporting the view definition, Oracle Data Pump exports a table definition and then unloads all data from the view. At import time, Oracle Data Pump creates a table using the table definition in the dump file and then inserts the data unloaded from the view into the table. The PL/SQL DBMS_DATAPUMP package has a similar option.

This feature allows greater flexibility in what a DBA can export. A view gives the DBA greater capability than the current WHERE parameter to specify a subset of the database to be unloaded. In a network mode import, exporting the contents of a view can achieve much better performance than using the impdp QUERY option.

对于Oracle数据泵导出,有一个新的expdp命令行选项,允许用户指出应该将视图导出为表。这意味着,Oracle数据泵不是导出视图定义,而是导出一个表定义,然后从视图中卸载所有数据。在导入时,Oracle数据泵在转储文件中使用表定义创建一个表,然后将从视图中卸载的数据插入到表中。PL / SQL DBMS_DATAPUMP包有类似的选项。

这个特性使DBA能够导出的内容更加灵活。视图赋予DBA更大的能力,而不是当前的WHERE参数指定要卸载的数据库的子集。在网络模式导入中,导出视图的内容可以比使用impdp查询选项获得更好的性能。

实验

语法:
VIEWS_AS_TABLES=[schema_name.]view_name,...
The VIEWS_AS_TABLES parameter can be used by itself or along with the TABLES parameter. If either is used, Data Pump performs a table-mode import.
The syntax elements are defined as follows:
schema_name--The name of the schema in which the view resides. If a schema name is not supplied, it defaults to the user performing the import.
view_name--The name of the view to be imported as a table.

1)创建视图
SQL> alter session set container=pdbcndba;

Session altered.

SQL> conn test/test@pdbcndba
Connected.

SQL> create or replace view vw_test as select OWNER,OBJECT_NAME,SUBOBJECT_NAME,OBJECT_ID from leo2;

View created.

SQL> select count(*) from vw_test;

  COUNT(*)
----------
     90936

SQL> select OBJECT_TYPE from all_objects where OWNER='TEST' and OBJECT_NAME ='VW_TEST';

OBJECT_TYPE
-----------------------
VIEW

2)导出视图
[oracle@host1 ~]$ expdp test/test@pdbcndba views_as_tables=test.vw_test directory=dpump_dir1 dumpfile=vw_test.dmp logfile=vw_test.log 

Export: Release 12.1.0.2.0 - Production on Fri Aug 4 17:33:43 2017

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

Connected to: Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options
Starting "TEST"."SYS_EXPORT_TABLE_01":  test/********@pdbcndba views_as_tables=test.vw_test directory=dpump_dir1 dumpfile=vw_test.dmp logfile=vw_test.log 
Estimate in progress using BLOCKS method...
Processing object type TABLE_EXPORT/VIEWS_AS_TABLES/TABLE_DATA
Total estimation using BLOCKS method: 16 KB
Processing object type TABLE_EXPORT/VIEWS_AS_TABLES/TABLE
. . exported "TEST"."VW_TEST"                            3.520 MB   90936 rows
Master table "TEST"."SYS_EXPORT_TABLE_01" successfully loaded/unloaded
******************************************************************************
Dump file set for TEST.SYS_EXPORT_TABLE_01 is:
  /backup/vw_test.dmp
Job "TEST"."SYS_EXPORT_TABLE_01" successfully completed at Fri Aug 4 17:33:45 2017 elapsed 0 00:00:01

可以看到视图和数据一并导出。
转储文件将包含一个名为vw_test的表,其中的行是从视图中提取的。
3) 删除视图,并将导出的视图vw_test.dmp文件导入数据中
SQL> drop view vw_test;                                                                

View dropped.

[oracle@host1 ~]$ impdp test/test@pdbcndba VIEWS_AS_TABLES=vw_test directory=dpump_dir1 dumpfile=vw_test.dmp logfile=vw_test2.log 

Import: Release 12.1.0.2.0 - Production on Fri Aug 4 17:34:30 2017

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

Connected to: Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options
Master table "TEST"."SYS_IMPORT_TABLE_01" successfully loaded/unloaded
Starting "TEST"."SYS_IMPORT_TABLE_01":  test/********@pdbcndba VIEWS_AS_TABLES=vw_test directory=dpump_dir1 dumpfile=vw_test.dmp logfile=vw_test2.log 
Processing object type TABLE_EXPORT/VIEWS_AS_TABLES/TABLE
Processing object type TABLE_EXPORT/VIEWS_AS_TABLES/TABLE_DATA
. . imported "TEST"."VW_TEST"                            3.520 MB   90936 rows
Job "TEST"."SYS_IMPORT_TABLE_01" successfully completed at Fri Aug 4 17:34:31 2017 elapsed 0 00:00:01
4)查看对象类型变为表,验证了View As a Table新特性
SQL> select OBJECT_TYPE from all_objects where OWNER='TEST' and OBJECT_NAME ='VW_TEST';

OBJECT_TYPE
-----------------------
TABLE

SQL> select count(*) from vw_test;

  COUNT(*)
----------
     90936

参考链接:

http://docs.oracle.com/database/121/SUTIL/GUID-E4E45E81-5391-43BE-B27D-B763EF79A885.htm#SUTIL3904

http://docs.oracle.com/database/121/SUTIL/GUID-DAB87784-6D0A-4CB7-A16F-DC3969133C88.htm#SUTIL3916

http://docs.oracle.com/database/121/SUTIL/GUID-D69908B3-298F-4DB2-B06C-88F6B683BC06.htm#SUTIL3921

猜你喜欢

转载自blog.csdn.net/leo__1990/article/details/90199330