Oracle---数据泵(增强逻辑导入导出)

 数据库连接(link----是一个对象)
//创建数据库连接
create database link link_stu1_scott useing 'stu1'; (stu3是配置好的服务端)  
create public database link link_5_scott connect to scott identified by tiger using '5';//创建所有人可用的数据库连接
//使用连接对象
desc emp@link_stu1_scott
select * from emp@link_stu1_scott;(查询连接到的服务段下的emp表)



数据泵:增强版的导入导出(oracle 10g版本之后才可用,只有在服务器端可用)
1.创建逻辑目录(使用逻辑目录来保存数据泵的备份文件)
conn scott/tiger
select * from all_firectories;
create or replace directory expbk as '/home/oracle/expbk';

2.授予scott用户读写逻辑目录的权限
grant read,write on directory expbk to scott;

实验1:使用数据泵导出元数据
expdp scott/tiger job_name=exp_ob1 directory=expbk tables=ob1 dumpfile=ob1_metadata.dmp content=metadata_only logfile=ob1_metadata.log

实验2:使用数据泵导出数据(不包含建表等命令)
expdp scott/tiger job_name=exp_ob1 directory=expbk tables=ob1 dumpfile=ob1_metadata.dmp
content=data_only logfile=ob1_metadata.log

实验3:使用数据泵导出数据和元数据
expdp scott/tiger job_name=exp_ob1 directory=expbk tables=ob1 dumpfile=ob1_metadata.dmp
content=all logfile=ob1_metadata.log

实验4:使用数据泵模糊匹配导出感兴趣的N张表
expdp scott/tiger job_name=exp_e directory=expbk include=table:\"like \'E%\'\" dumpfile=e.dmp logfile=e.log
      导出带有特殊字符或者大小写敏感的表
expdp scott/tiger job_name=exp_e directory=expbk include=table:\"like \'123\'\" dumpfile=e.dmp logfile=e.log    

实验5:使用数据泵模糊匹配屏蔽不想导出的N张表
expdp scott/tiger job_name=exp_e directory=expbk exclude=table:\"like \'E%\'\" dumpfile=scott_not_e.dmp logfile=e.log

实验6:使用数据泵导入
impdp scott/tiger directory=expbk dumpfile=ob1.dmp logfile=imp_ob1.log

实验7:使用数据泵导出用户所有数据
expdp scott/tiger directory=expbk dumpfile=scott.dmp parallel=8 job_name=scott_job schemas=scott content=all logfile=scott.log

实验8:使用数据库链接将scott数据映射到u1
conn system/oracle
grant connect,resource to u1 identified by u1;
create public database link link_local_system connect to system
identified by oracle using 'stu250';
impdp system/oracle network_link=link_local_system schemas=scott remap_schema=scott:u1

实验9:使用数据泵导出表空间数据
expdp scott/tiger directory=expbk dumpfile=users.dmp parallel=8 job_name=users_job tablespaces=users content=all logfile=users.log

实验10:闪回导出
expdp system/uplooking directory=expbk tables=scott.emp dumpfile=emp.dmp logfile=emp.log flashback_time=\(sysdate-4/1440\)

expdp system/uplooking directory=expbk tables=scott.emp dumpfile=emp.dmp logfile=emp.log flashback_time=\"to_timestamp\(\'20170622 15:00:00\',\'yyyymmdd hh24:mi:ss\'\)\"

实验11:导入时更改表名
impdp userid=scott/tiger directory=expbk dumpfile=e01.dmp log=e01.log tables=e01 remap_table=e01:e03

实验12:导入时更改表空间
impdp userid=scott/tiger directory=expbk dumpfile=e01.dmp log=e01.log tables=e01 remap_tablespace=system:tbs1

实验13:导入时更改用户
impdp userid=system/oracle directory=expbk dumpfile=e01.dmp log=e01.log tables=scott.e01 remap_schema=scott:tom

实验14: sqlfile 将ddl语句写入脚本文件,类似于imp的show=y
impdp userid=system/oracle directory=expbk dumpfile=e01.dmp log=e01.log tables=scott.e01 remap_schema=scott:tom transform=storage:n sqlfile=e02.sql


实验15:导出时修改某一列的数据
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
创建修改数据的函数,函数必须属于package
create or replace package pk_remap
is
function modify_sal
(p_sal number)
return number;
end;
/

create or replace package body pk_remap
is
function modify_sal
(p_sal number)
return number
is
  v_sal number;
begin
  v_sal:=round(dbms_random.value(1,p_sal));
  return v_sal;
end;
end;
/

expdp userid=scott/tiger directory=expbk dumpfile=e01.dmp reuse_dumpfiles=y job_name=test_job logfile=e01.log  tables=e01 remap_data=scott.e01.sal:scott.pk_remap.modify_sal
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

实验16:使用数据泵传输表空间
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
alter tablespace teach10 read only;
expdp \'sys/oracle as sysdba\' directory=expbk dumpfile=teach10.dmp tablespaces=teach10 transport_tablespace=y logfile=teach10.log

scp teach10.dmp oracle@172.25.18.11:/home/oracle/
scp /home/oracle/teach10.dbf oracle@172.25.18.11:/demo/teach10.dbf

create or replace directory expbk as '/home/oracle';

impdp \'sys/oracle as sysdba\' directory=expbk dumpfile=teach10.dmp logfile=impteach10.log transport_datafiles=\'/demo/teach10.dbf\'
alter tablespace teach10 read write;
alter tablespace teach10 read write;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

实验17:使用数据泵导出全库:
expdp system/oracle directory=expbk dumpfile=orcl.dmp parallel=8 job_name=orcl_job full=y logfile=orcl.log

实验18:使用数据泵导出远程数据
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
在0号机创建数据库链接导出5号机的表
172.25.0.10:
create public database link link_5_scott connect to scott identified by tiger using '5';
//创建所有人可用的数据库连接
expdp scott/tiger network_link=link_5_scott directory=expbk dumpfile=test_expdp_5.dmp tables=test_expdp_5

在5号机创建数据库链接,连接到5号机的scott将0号机的表导入到5号机
172.25.0.10:
sqlplus sys/oracle@5 as sysdba
create public database link link_0_scott connect to scott identified by tiger using '10';

impdp scott/tiger@5 network_link=link_0_scott directory=expbk tables=t001  //不需要dump文件,走数据库连接,本地先连到5号机,走数据库连接将0号机的t001表导到5号机



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值