1. 程式人生 > >expdp與impdp匯出匯入指定表

expdp與impdp匯出匯入指定表

oracle裡指定匯入匯出表,原本在10g或以前,很簡單的:

一、10g或以前

1、匯出指定表
exp 'sys/[email protected] as sysdba' file=c:\temp\tables.dmp tables=(schema1.table1,schema1.table2)

2、匯入指定表
imp 'sys/[email protected] as sysdba' file=c:\temp\tables.dmp fromuser=schema1 touser=schema1 tables=(table1,table2) ignore=Y

二、11g或12c
但12C以後,似乎就不支援這種寫法了。可以這樣寫:

1、匯出指定表
expdp 'sys/[email protected] as sysdba' directory=dbbak dumpfile=tables.dmp logfile=tables.log tables=schema1.table1,schema1.table2

2、匯入指定表
impdp 'sys/[email protected] as sysdba' directory=dbbak dumpfile=tables.dmp tables=schema1.table1,schema1.table2  REMAP_SCHEMA=schema1:schema1
--REMAP_SCHEMA=schema1:schema1,源庫shema:目標庫schema

其中,dbbak沒有的話,要先建立:

在sqlplus下:

create directory dbbak as 'c:\temp';--(手動建立temp資料夾)
grant read,write on directory dbbak to public;

這個dbbak是個啥東東呢?據說資料庫某種程度上類似一個作業系統,它有自己的一套磁碟管理機制,一般不直接使用作業系統的檔案系統。甚至乎,它希望直接使用“生磁碟”,就是沒有格式化過的磁碟。所以,dbbak是一個磁碟路徑對映,要將作業系統下的路徑對映到oracle裡,才能使用。

以上這個expdp,impdp匯出匯入指定表,網上搜了之後,發覺很少有直接能使用的例子,我這兩個還是綜合起來,經過一些測試才通過的。