場景:有2個oracle用戶,userA默認表空間tablespaceA, userB默認表空間tablespaceB。
現在需要將userA中的系統表(該用戶表空間中以SYS開頭的表)導出到userB中,將userB的系統表覆蓋,但不覆蓋userB的業務表。方法如下:
導出userA用戶schema中SYS開頭的表,使用tables=SYS%
expdp userA/password directory=TMP_BAK dumpfile=userA-170504-expdp-tab.dmp logfile=userA-170504-expdp-tab.log tables=SYS%
若只需導出某幾張表,則使用tables=table1,table2
expdp userA/password directory=TMP_BAK dumpfile=userA-170504-expdp-tab02.dmp logfile=userA-170504-expdp-tab02.log tables=table1,table2
將導出的dmp文件導入到userB用戶的schema中。
需要注意此處SCHEMA與表對應的TABLESPACE已經發生改變,並且原userB的表空間中已經存在SYS表。故導入時需要加上以下幾個參數:
①remap_schema指定源SCHEMA與目的SCHEMA。
②remap_tablespace指定源TABLESPACE與目的TABLESPACE。
③ table_exists_action=replace將重名錶進行覆蓋。
導入前注意先備份userB的數據,避免導出出錯造成數據丟失。
expdp userB/password directory=TMP_BAK dumpfile=userB-170504-expdp.dmp logfile=userB-170504-expdp.log
正式將SYS開頭的表導入userB用戶中。
impdp userB/password directory=TMP_BAK dumpfile=userA-170504-expdp-tab.dmp remap_schema=userA:userB REMAP_TABLESPACE=tablespaceA:tablespaceB TABLE_EXISTS_ACTION=REPLACE logfile=userB-0504-impdp-tab.log