原文連接:http://www.2cto.com/database/201211/171081.htmlhtml
將DMP導入到不一樣的表空間中sql
1,用imp導出數據 cmd進入orcle安裝目錄bin下,輸入如下命令:
exp username/password@ORACLEEPP file=c:\hysjb.dmp owner=magazine_hy rows=y
2, 用imp產生index.sql文件
imp <xe_username>/<password>@XE file=<filename.dmp> indexfile=index.sql full=y
3,修改index.sql文件
FIND: 'REM<SPACE>' REPLACE: <NOTHING>
FIND: '"<SOURCE_TABLESPACE>"' REPLACE: '"USERS"'
FIND: '...' REPLACE: 'REM ...'
FIND: 'CONNECT' REPLACE: 'REM CONNECT'
ps:查看錶空間的語句:
select
df.tablespace_name "TABLESPACE_NAME",totalspace "TOTALSPACE/M",freespace "FREESPACE/M",round((1-freespace/totalspace)*100,2) "USED%"
from
(select tablespace_name,round(sum(bytes)/1024/1024) totalspace from dba_data_files group by tablespace_name) df,
(select tablespace_name,round(sum(bytes)/1024/1024) freespace from dba_free_space group by tablespace_name) fs
where df.tablespace_name=fs.tablespace_name;
4,使用sqlplus進入執行此sql生成表結構
sqlplus <xe_username>/<password>@XE @index.sql
5,進入數據庫diasble掉依賴。
select 'ALTER TABLE '||table_name|| ' disable constraint '||constraint_name|| '; ' from user_constraints
where constraint_type = 'R';
導出csv文件爲imp.sql,刪除"號,執行。
6,導入數據,cmd下執行:
imp <xe_username>/<password>@XE file=<filename.dmp> fromuser=<original_username> touser=<xe_username> ignore=y
7,將imp.sql中的disable替換成enable執行。enable依賴數據庫
小龍評論spa
第3步可能搜不到全部須要替換的內容,另外可能最終獲得的結果沒法正確執行。那就把sql挑出來單獨執行便可htm
FIND 'REM ' REPLACE' 'get
FIND '... 0 rows' REPLACE ' 'cmd
第5步、第7步,若是是導入到新的數據庫,就不用再禁用、啓用約束。table