資料泵避免個別表資料的匯出
對於資料泵EXPDP/IMPDP而言,功能比普通EXP/IMP功能要強的多,因此也可以實現一些普通匯出匯入工具很難完成的工作。
比如今天碰到的這個問題,要匯出一些表,但是其中個別表只匯出結構而不匯出資料。
SQL> conn test/test
Connected.
SQL> set pages 100 lines 120
SQL> select count(*) from t;
COUNT(*)
----------
23
SQL> select count(*) from tt;
COUNT(*)
----------
72
SQL> exit
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production
With the Partitioning, OLAP and Data Mining options
[oracle@yans1 ~]$ expdp test/test directory=d_output dumpfile=t_tt1.dp tables=(t,tt)
Export: Release 10.2.0.3.0 - 64bit Production on 星期二, 25 8月, 2009 16:04:58
Copyright (c) 2003, 2005, Oracle. All rights reserved.
Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production
With the Partitioning, OLAP and Data Mining options
Starting "TEST"."SYS_EXPORT_TABLE_01": test/******** directory=d_output dumpfile=t_tt1.dp tables=(t,tt)
Estimate in progress using BLOCKS method...
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 256 KB
Processing object type TABLE_EXPORT/TABLE/TABLE
Processing object type TABLE_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
. . exported "TEST"."T" 5.953 KB 23 rows
. . exported "TEST"."TT" 6.421 KB 72 rows
Master table "TEST"."SYS_EXPORT_TABLE_01" successfully loaded/unloaded
******************************************************************************
Dump file set for TEST.SYS_EXPORT_TABLE_01 is:
/home/oracle/t_tt1.dp
Job "TEST"."SYS_EXPORT_TABLE_01" successfully completed at 16:05:02
用T和TT表作為例子,分別代表需要匯出結構的表和同時包含結構和資料的表。
這個需求對於普通的EXP/IMP來說,只能透過兩次匯出操作來完成,一次匯出包含資料的表,另一個透過執行ROWS=N匯出僅需要結構的表。
對於EXPDP來說,同樣可以使用類似的方法,引數CONTENT控制匯出的結構、資料還是全部:
[oracle@yans1 ~]$ expdp test/test directory=d_output dumpfile=t_tt2.dp tables=(t,tt) content=metadata_only
Export: Release 10.2.0.3.0 - 64bit Production on 星期二, 25 8月, 2009 16:32:59
Copyright (c) 2003, 2005, Oracle. All rights reserved.
Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production
With the Partitioning, OLAP and Data Mining options
Starting "TEST"."SYS_EXPORT_TABLE_01": test/******** directory=d_output dumpfile=t_tt2.dp tables=(t,tt) content=metadata_only
Processing object type TABLE_EXPORT/TABLE/TABLE
Processing object type TABLE_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
Master table "TEST"."SYS_EXPORT_TABLE_01" successfully loaded/unloaded
******************************************************************************
Dump file set for TEST.SYS_EXPORT_TABLE_01 is:
/home/oracle/t_tt2.dp
Job "TEST"."SYS_EXPORT_TABLE_01" successfully completed at 16:33:02
但是這種方法控制的是整體,現在需要對其中的個別物件只匯出表結構。最好想到的方法是透過QUERY來控制:
[oracle@yans1 ~]$ expdp test/test directory=d_output dumpfile=t_tt3.dp tables=(t,tt) query='t:"where 1=2"'
Export: Release 10.2.0.3.0 - 64bit Production on 星期二, 25 8月, 2009 16:51:37
Copyright (c) 2003, 2005, Oracle. All rights reserved.
Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production
With the Partitioning, OLAP and Data Mining options
Starting "TEST"."SYS_EXPORT_TABLE_01": test/******** directory=d_output dumpfile=t_tt3.dp tables=(t,tt) query=t:"where 1=2"
Estimate in progress using BLOCKS method...
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 256 KB
Processing object type TABLE_EXPORT/TABLE/TABLE
Processing object type TABLE_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
. . exported "TEST"."T" 5.507 KB 0 rows
. . exported "TEST"."TT" 6.421 KB 72 rows
Master table "TEST"."SYS_EXPORT_TABLE_01" successfully loaded/unloaded
******************************************************************************
Dump file set for TEST.SYS_EXPORT_TABLE_01 is:
/home/oracle/t_tt.dp
Job "TEST"."SYS_EXPORT_TABLE_01" successfully completed at 16:51:41
透過對T表新增一個恆為FALSE的查詢條件,使得T表匯出的時候獲取0條記錄,從而達到只導T的結構的目的。
但是這種方法對於資料量比較大的表效率會比較低,因為Oracle會進行匯出的操作,只是在處理的時候將記錄過濾掉,除了沒有將資料寫到匯出檔案,其他所有的操作都進行了,因此效率很低。
而實際上,資料泵還有更好的辦法來解決這個問題:使用EXCLUDE引數。
[oracle@yans1 ~]$ expdp test/test directory=d_output dumpfile=t_tt4.dp tables=(t,tt) exclude=table/table_data:\"=\'T\'\"
Export: Release 10.2.0.3.0 - 64bit Production on 星期二, 25 8月, 2009 16:59:39
Copyright (c) 2003, 2005, Oracle. All rights reserved.
Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production
With the Partitioning, OLAP and Data Mining options
Starting "TEST"."SYS_EXPORT_TABLE_01": test/******** directory=d_output dumpfile=t_tt4.dp tables=(t,tt) exclude=table/table_data:"='T'"
Estimate in progress using BLOCKS method...
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 128 KB
Processing object type TABLE_EXPORT/TABLE/TABLE
Processing object type TABLE_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
. . exported "TEST"."TT" 6.421 KB 72 rows
Master table "TEST"."SYS_EXPORT_TABLE_01" successfully loaded/unloaded
******************************************************************************
Dump file set for TEST.SYS_EXPORT_TABLE_01 is:
/home/oracle/t_tt4.dp
Job "TEST"."SYS_EXPORT_TABLE_01" successfully completed at 16:59:43
這裡看不到T表的資訊,下面檢查一下匯出是否生效:
[oracle@yans1 ~]$ sqlplus test/test
SQL*Plus: Release 10.2.0.3.0 - Production on 星期二 8月 25 17:00:27 2009
Copyright (c) 1982, 2006, Oracle. All Rights Reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production
With the Partitioning, OLAP and Data Mining options
SQL> desc t
Name Null? Type
----------------------------------------- -------- ----------------------------
ID NUMBER
NAME NOT NULL VARCHAR2(30)
TYPE VARCHAR2(7)
SQL> drop table t;
Table dropped.
SQL> exit
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production
With the Partitioning, OLAP and Data Mining options
[oracle@yans1 ~]$ impdp test/test directory=d_output dumpfile=t_tt4.dp tables=t
Import: Release 10.2.0.3.0 - 64bit Production on 星期二, 25 8月, 2009 17:00:41
Copyright (c) 2003, 2005, Oracle. All rights reserved.
Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production
With the Partitioning, OLAP and Data Mining options
Master table "TEST"."SYS_IMPORT_TABLE_01" successfully loaded/unloaded
Starting "TEST"."SYS_IMPORT_TABLE_01": test/******** directory=d_output dumpfile=t_tt4.dp tables=t
Processing object type TABLE_EXPORT/TABLE/TABLE
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
Processing object type TABLE_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
Job "TEST"."SYS_IMPORT_TABLE_01" successfully completed at 17:00:43
[oracle@yans1 ~]$ sqlplus test/test
SQL*Plus: Release 10.2.0.3.0 - Production on 星期二 8月 25 17:00:47 2009
Copyright (c) 1982, 2006, Oracle. All Rights Reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production
With the Partitioning, OLAP and Data Mining options
SQL> desc t
Name Null? Type
----------------------------------------- -------- ----------------------------
ID NUMBER
NAME NOT NULL VARCHAR2(30)
TYPE VARCHAR2(7)
SQL> select * from t;
no rows selected
很顯然,利用EXCLUDE的方式使得資料泵匯出的時候去掉了T表的資料。
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29067253/viewspace-2135132/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 資料泵避免個別表資料的匯出(二)
- 資料泵匯出匯入表
- Oracle使用資料泵匯出匯入表Oracle
- 資料泵的匯入匯出
- 資料泵匯出匯入
- 12c 資料泵匯入匯出級別
- 資料泵匯出匯入資料標準文件
- 細緻入微:如何使用資料泵匯出表的部分列資料
- Oracle資料泵的匯入和匯出Oracle
- Oracle資料泵-schema匯入匯出Oracle
- 使用資料泵工具expdp工具匯出資料
- 資料泵匯出資料包錯處理
- 【資料泵】EXPDP匯出表結構(真實案例)
- 資料泵過濾匯出資料的where條件
- Oracle資料泵匯出匯入(expdp/impdp)Oracle
- 資料泵取匯出和匯入(一)
- 資料泵匯出索引資料和統計資訊嗎索引
- 資料泵無法匯出sys使用者下的表
- Oracle使用資料泵expdp,impdp進行資料匯出匯入Oracle
- Oracle使用資料泵在異機之間匯出匯入表Oracle
- Oracle expdp資料泵遠端匯出Oracle
- 使用資料泵匯出DDL語句
- 轉oracle資料泵匯出時報錯Oracle
- 資料庫泵(expdp/impdp)匯入匯出流程資料庫
- 用資料泵併發匯入資料的一個案例
- 使用資料泵impdp匯入資料
- 資料泵在本地匯出資料到遠端資料庫中資料庫
- mysql匯出某個表的部分資料MySql
- Impdp資料泵匯入
- Progress資料表的匯入匯出
- 【匯入匯出】資料泵 job_name引數的使用
- mysqldump匯入匯出表資料MySql
- DB2資料庫匯出表結構與匯入、匯出表資料DB2資料庫
- python實現oracle資料泵匯出功能PythonOracle
- oracle 資料泵匯出簡單使用版Oracle
- 利用資料泵匯出查詢結果(二)
- 利用資料泵匯出查詢結果(一)
- expdp匯出表的部分資料