對比資料泵與原始匯入匯出工具(六)
Oracle的匯入匯出工具EXP/IMP由來已久,大部分人對於使用這兩個工具也都不陌生。Oracle10g開始推出的資料泵EXPDP/IMPDP,提供了匯入匯出的效能,也增加了匯入匯出的功能,但是由於使用時間不長,可能部分人對這個工具不太瞭解。一直打算寫幾篇文章,簡單描述一下EXP/IMP和EXPDP/IMPDP的差異。
對比資料泵與原始匯入匯出工具(一):http://yangtingkun.itpub.net/post/468/476017
對比資料泵與原始匯入匯出工具(二):http://yangtingkun.itpub.net/post/468/476060
對比資料泵與原始匯入匯出工具(三):http://yangtingkun.itpub.net/post/468/477335
對比資料泵與原始匯入匯出工具(四):http://yangtingkun.itpub.net/post/468/477380
對比資料泵與原始匯入匯出工具(五):http://yangtingkun.itpub.net/post/468/477633
這篇描述資料泵的QUERY引數。
去年年初開始了這個系列文章,當時正在看工具手冊,因此對資料泵和原始匯入匯出EXP/IMP的差異比較有心得,不過當時只寫了一部分,這兩天整理的時候發現,於是打算再續寫幾篇。
Oracle在EXP/IMP時已經支援QUERY引數,不過那是的QUERY引數要求比較嚴格,必須匯出的所有表都滿足QUERY引數的查詢條件,使得QUERY引數的使用有很大的侷限性:
SQL> CREATE TABLE T1
2 (ID NUMBER PRIMARY KEY,
3 NAME VARCHAR2(30),
4 TYPE VARCHAR2(30));
Table created.
SQL> CREATE TABLE T2
2 (ID NUMBER PRIMARY KEY,
3 FID NUMBER,
4 NAME VARCHAR2(30),
5 CONSTRAINT FK_T2 FOREIGN KEY (FID) REFERENCES T1 (ID));
Table created.
SQL> INSERT INTO T1
2 VALUES (1, 'T1', 'TABLE');
1 row created.
SQL> INSERT INTO T1
2 VALUES (2, 'T2', 'TABLE');
1 row created.
SQL> INSERT INTO T1
2 VALUES (3, 'FK_T2', 'CONSTRAINT');
1 row created.
SQL> INSERT INTO T2
2 VALUES (1, 1, 'PK_T1');
1 row created.
SQL> INSERT INTO T2
2 VALUES (2, 2, 'PK_T2');
1 row created.
SQL> COMMIT;
Commit complete.
[oracle@yans1 ~]$ exp test/test file=t1_t2.dmp tables=t1,t2 query=\"where id = 1\"
Export: Release 10.2.0.3.0 - Production on 星期一 8月 23 22:42:20 2010
Copyright (c) 1982, 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
Export done in ZHS16GBK character set and AL16UTF16 NCHAR character set
About to export specified tables via Conventional Path ...
. . exporting table T1 1 rows exported
. . exporting table T2 1 rows exported
Export terminated successfully without warnings.
[oracle@yans1 ~]$ exp test/test file=t1_t2.dmp tables=t1,t2 query=\"where type = \'TABLE\'\"
Export: Release 10.2.0.3.0 - Production on 星期一 8月 23 22:42:48 2010
Copyright (c) 1982, 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
Export done in ZHS16GBK character set and AL16UTF16 NCHAR character set
About to export specified tables via Conventional Path ...
. . exporting table T1 2 rows exported
. . exporting table T2
EXP-00056: ORACLE error 904 encountered
ORA-00904: "TYPE": invalid identifier
Export terminated successfully with warnings.
對於T1和T2都成立的查詢WHERE ID = 1,使用QUERY語句可以正常工作,而對於WHERE TYPE = ‘TABLE’來說,只對T1成立,因此匯出T2時報錯。
而資料泵則沒有這個限制,資料泵在指定QUERY語句的時候需要明確指定表名,因此完全可以實現上面的功能:
[oracle@yans1 ~]$ expdp test/test directory=d_output dumpfile=t1_t2.dp tables=t1,t2 query="T1:\"WHERE TYPE = 'TABLE'\""
Export: Release 10.2.0.3.0 - 64bit Production on 星期一, 23 8月, 2010 23:00:32
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=t1_t2.dp tables=t1,t2 query=T1:"WHERE TYPE = 'TABLE'"
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/CONSTRAINT/CONSTRAINT
Processing object type TABLE_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINT
. . exported "TEST"."T1" 5.539 KB 2 rows
. . exported "TEST"."T2" 5.539 KB 2 rows
Master table "TEST"."SYS_EXPORT_TABLE_01" successfully loaded/unloaded
******************************************************************************
Dump file set for TEST.SYS_EXPORT_TABLE_01 is:
/home/oracle/t1_t2.dp
Job "TEST"."SYS_EXPORT_TABLE_01" successfully completed at 23:00:36
由於資料泵的這個功能,可以為不同的表指定不同的查詢語句,比如:
[oracle@yans1 ~]$ expdp test/test directory=d_output dumpfile=t1_t2_2.dp tables=t1,t2 query='T1:"WHERE ID = 1"' query='T2:"WHERE FID = 1"'
Export: Release 10.2.0.3.0 - 64bit Production on 星期一, 23 8月, 2010 23:03:28
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=t1_t2_2.dp tables=t1,t2 query=T1:"WHERE ID = 1" query=T2:"WHERE FID = 1"
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/CONSTRAINT/CONSTRAINT
Processing object type TABLE_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINT
. . exported "TEST"."T1" 5.523 KB 1 rows
. . exported "TEST"."T2" 5.523 KB 1 rows
Master table "TEST"."SYS_EXPORT_TABLE_01" successfully loaded/unloaded
******************************************************************************
Dump file set for TEST.SYS_EXPORT_TABLE_01 is:
/home/oracle/t1_t2_2.dp
Job "TEST"."SYS_EXPORT_TABLE_01" successfully completed at 23:03:32
資料泵的QUERY功能的強大之處還體現在,不僅EXPDP支援,IMPDP也支援查詢引數,而對於原始匯入匯出工具來說,只有EXP支援QUERY引數:
[oracle@yans1 ~]$ expdp test/test directory=d_output dumpfile=t2.dp tables=t2
Export: Release 10.2.0.3.0 - 64bit Production on 星期一, 23 8月, 2010 23:13:17
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=t2.dp tables=t2
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/CONSTRAINT/CONSTRAINT
Processing object type TABLE_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINT
. . exported "TEST"."T2" 5.539 KB 2 rows
Master table "TEST"."SYS_EXPORT_TABLE_01" successfully loaded/unloaded
******************************************************************************
Dump file set for TEST.SYS_EXPORT_TABLE_01 is:
/home/oracle/t2.dp
Job "TEST"."SYS_EXPORT_TABLE_01" successfully completed at 23:13:21
匯出T2全部,下面TRUNCATE T2表:
SQL> TRUNCATE TABLE T2;
Table truncated.
使用QUERY方式匯入部分資料:
[oracle@yans1 ~]$ impdp test/test directory=d_output dumpfile=t2.dp tables=t2 query='T2:"WHERE ID = 1"' table_exists_action=append
Import: Release 10.2.0.3.0 - 64bit Production on 星期一, 23 8月, 2010 23:14:56
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=t2.dp tables=t2 query=T2:"WHERE ID = 1" table_exists_action=append
Processing object type TABLE_EXPORT/TABLE/TABLE
ORA-39152: Table "TEST"."T2" exists. Data will be appended to existing table but all dependent metadata will be skipped due to table_exists_action of append
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
. . imported "TEST"."T2" 5.539 KB 1 out of 2 rows
Processing object type TABLE_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
Processing object type TABLE_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINT
Job "TEST"."SYS_IMPORT_TABLE_01" completed with 1 error(s) at 23:14:58
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/4227/viewspace-671683/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 對比資料泵與原始匯入匯出工具(五)
- 對比資料泵與原始匯入匯出工具(四)
- 對比資料泵與原始匯入匯出工具(三)
- 對比資料泵與原始匯入匯出工具(八)
- 對比資料泵與原始匯入匯出工具(七)
- 10g資料泵和匯入匯出效能對比(六)
- 資料泵匯出匯入
- 10g資料泵和匯入匯出效能對比(三)
- 10g資料泵和匯入匯出效能對比(二)
- 10g資料泵和匯入匯出效能對比(一)
- 10g資料泵和匯入匯出效能對比(四)
- 10g資料泵和匯入匯出效能對比(五)
- 資料泵的匯入匯出
- 資料泵匯出匯入表
- Oracle資料泵-schema匯入匯出Oracle
- Oracle資料泵的匯入和匯出Oracle
- Oracle資料泵匯出匯入(expdp/impdp)Oracle
- Oracle使用資料泵匯出匯入表Oracle
- 資料泵取匯出和匯入(一)
- 資料泵匯出匯入資料標準文件
- 資料庫泵(expdp/impdp)匯入匯出流程資料庫
- 使用資料泵工具expdp工具匯出資料
- 【原創】比較資料泵和exp/imp對相同資料匯出/匯入的效能差異
- 12c 資料泵匯入匯出級別
- 資料泵IMPDP 匯入工具的使用
- 資料泵引數彙總與各種匯出匯入規則
- 針對資料泵匯出 (expdp) 和匯入 (impdp)工具效能降低問題的檢查表
- Oracle使用資料泵expdp,impdp進行資料匯出匯入Oracle
- MySQL資料匯入匯出方法與工具介紹MySql
- Impdp資料泵匯入
- MongoDB資料匯入與匯出MongoDB
- 資料泵匯出匯入物化檢視(ORA-39083)
- oracle10G新特性之資料泵匯出/匯入Oracle
- 【匯入匯出】資料泵 job_name引數的使用
- Mongodb資料的匯出與匯入MongoDB
- MySQL表資料匯入與匯出MySql
- AWR資料的匯出與匯入
- Mysql 資料庫匯入與匯出MySql資料庫