---
title: "数据迁移"
author: "wsql"
date: "2013-03-15T08:50:00Z"
tags: []
slug: "untitled"
draft: false
lastmod: "2013-03-25T11:49:30Z"
id: 1836032
url: "https://wsql.iteye.com/blog/1836032"
---

1、数据泵导入导出  
create directory dump\_file\_dir as '/home/oracle/';  
grant read,write on directory dump\_file\_dir to gyj;  
expdp gyj/gyj directory=dump\_file\_dir dumpfile=gyj20121117.dmp nologfile=y;  
create user gyj1 identified by gyj1 default tablespace t2;  
grant dba to gyj1;  
impdp test1/test1 directory=dump\_file\_dir dumpfile=gyj20120922.dmp remap\_schema=gyj:test1 remap\_tablespace=USERS:TP50,TP2:TP50,TP12:TP50 nologfile=y  
注:select * from dba\_datapump\_jobs;  
expdp gyj/gyj attach=gyj1.SYS\_EXPORT\_SCHEMA\_01;  
kill--&gt;yes(kill\_job此命令在11g中不能用);

2、表空间传输(Transportable Tablespace):OLTP  
A库:  
exec dbms\_tts.transport\_set\_check('OLTP',true); //检查是否自包含(如索引,分区表,CLOB等不在一个表空间就不是自包含)  
select * from transport\_set\_violations; //如果返回为空说明满足自包含  
create directory dir\_prod as ‘/home/oracle/dir’;  
alter tablespace oltp read only;  
expdp system/oracle dumpfile=oltp.dmp directory=dir\_prod TRANSPORT\_TABLESPACES=oltp;  
scp /u01/app/oracle/oradata/PROD/Disk1/oltp1.dbf oracle@192.168.0.3:/u01/app/oracle/oradata/EMREP/  
scp /home/oracle/dir/oltp.dmp oracle@192.168.0.3:/home/oracle/dir  
B库:  
create directory dir\_prod as ‘/home/oracle/dir’;  
create user oltp\_user identified by oracle;  
grant dba to oltp\_user;  
impdp system/oracle@emrep dumpfile='oltp.dmp' directory= dir\_emrep transport\_datafiles='/u01/app/oracle/oradata/EMREP/oltp1.dbf','/u01/app/oracle/oradata/EMREP/batch.dbf'  
A、B库：  
alter tablespace oltp read write;  
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\**  
alter database mount;  
alter database datafile '/u01/app/oracle/oradata/bxdb/tp1.dbf' offline drop ;  
alter database open;  
drop tablespace tp1 including contents and datafiles cascade constraints;

\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\**

3、SQL\*Loader  
(1)建表  
create table gyj\_yktjsxxb(sfzh varchar2(20),xm varchar2(20));  
(2)记事本中的数据  
vi t\_jzgxx\_sm.txt  
432325197810254019|Tom|  
433101196303180048|Joe|  
433101195709120024|Rose|  
43310119691229004x|Jack|  
433101196711270050|Linda|  
433101197306101514|Jeny|

vi ytkjsxx.ctl  
load data  
infile '/home/oracle/t\_jzgxx\_sm.txt'  
into table gyj\_yktjsxxb  
fields terminated by '|'  
(sfzh,xm)

sqlldr userid=gyj/gyj control=/home/oracle/ytkjsxx.ctl

4、外部表  
(1)、Loader生成外部表加载文件：Administrator's Guide 15章结尾 create external table  
In the scripts directory, you will find prod\_master.dat and prod\_master.ctl. Using the information found in these files,  
create an external table names PROD\_MASTER in the SH schema of the PROD database.  
\[oracle@rptdb1 external]$ cat prod\_master.ctl  
load data  
infile '/home/oracle/dir/prod\_master.dat'  
append  
into table costs  
fields terminated by ","  
(channel\_id,prod\_id,promo\_id,time\_id,unit\_cost,unit\_price)  
\[oracle@rptdb1 external]$  
\[oracle@rptdb1 external]$ cat prod\_master.dat  
6,6,6,6,6,600  
7,7,7,7,7,700

create directory dir as '/opt/oracrs/external';  
grant read,write on directory dir to sh;  
create table costs(channel\_id number,prod\_id number,promo\_id number,time\_id number,unit\_cost number,unit\_price number  
);  
sqlldr gyj/gyj control=prod\_master.ctl external\_table=GENERATE\_ONLY

(2)、Datapump外部表卸载：Database Data Warehousing Guide 12章结尾部分Extracting into Export Files Using External Tables  
CREATE TABLE ext\_t1  
ORGANIZATION external  
(  
TYPE ORACLE\_DATAPUMP  
DEFAULT DIRECTORY dump\_file\_dir  
location ('t1.dat')  
)  
as SELECT * FROM T1 WHERE ID=1;

(3)、Datapump外部表加载  
SQL&gt; create table ext\_t1  
(id number,  
name varchar2(100)  
)  
organization external  
(  
type oracle\_datapump  
default directory DUMP\_FILE\_DIR  
location ('t1.dat')

);

\*\*\*\*\*\*\*\*\*\*本博客所有内容均为原创，如有转载请注明作者和出处!!!\*\*\*\*\*\*\*\*\**  
Name: guoyJoe

QQ: 252803295

Email: oracledba\_cn@hotmail.com

Blog:[http://blog.csdn.net/guoyJoe](http://blog.csdn.net/guoyJoe)

ITPUB:[http://www.itpub.net/space-uid-28460966.html](http://www.itpub.net/space-uid-28460966.html)

OCM:[http://education.oracle.com/education/otn/YGuo.HTM](http://education.oracle.com/education/otn/YGuo.HTM)  
\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\__  
加群验证问题：哪些SGA结构是必需的，哪些是可选的？否则拒绝申请!!!

答案在：[http://blog.csdn.net/guoyjoe/article/details/8624392](http://blog.csdn.net/guoyjoe/article/details/8624392)

Oracle@Paradise 　总群:127149411

Oracle@Paradise No.1群:177089463(已满)

Oracle@Paradise No.2群:121341761

Oracle@Paradise No.3群:140856036