优点:
1)由于只能将导出的转储文件放在DIRECTORY对象对应的OD目录中,而不能指定。所以需要先建立DIRECTORY对象,并且具有使用DIRECTORY对象的权限。
2) 导出其他用户方案中的表,需要有DBA或者EXP_FULL_DATABASE角色
3) 一次只能导出一个方案中的表
实例:
创建一个DIRECTORY对象,并授予SCOTT使用权限
# d:\app\dump 目录是需要提前建好的
# 这里的 create directory只是建立逻辑对象
SQL> create directory dump_dir as 'd:\app\dump';
SQL> grant read,write on directory dump_dir to scott;
实例:
导出scott用户的emp和dept表到转出文件tab.dmp
D:\app>expdp scott/password directory=dump_dir dumpfile=tab.dmp tables=emp,dept
DBA
、EXP_FULL_DATABASE
角色实例:
将scott,hr方案中的所有对象存储到文件schema.dmp中
D:\app>expdp scott/password directory=dump_dir dumpfile=schema.dmp schemas=scott,hr
DBA
、EXP_FULL_DATABASE
角色create TABLESPACE TBSP_1 DATAFILE 'D:\app\Administrator\oradata\oracle\tbsp_1.dbf' SIZE 10M;
D:\app>expdp scott/password directory=dump_dir dumpfile=tablespace.dmp schemas=tbsp_1
实例:
导出整个数据库
D:\app>expdp scott/password directory=dump_dir dumpfile=fulldatabase.dmp full=y
content参数,默认值为 ALL
EXPDP HELP
命令,可了解其各个参数的信息
D:\app>expdp scott/password directory=dump_dir dumpfile=content.dmp content=data_only
query参数,指定过滤导出数据的where条件
语法:
query=[schema.][table_name:]query_clause
content=metadata_only extimate_only、transport_tablespaces
等参数同时使用实例:
通过QUERY
参数过滤导出dept表中部门编号为10的数据
D:\app>expdp scott/password directory=dump_dir dumpfile=query.dump tables=emp query='where deptno=10 '
dump_dir 需要在此用户下创建好:
SQL> create directory dump_dir as 'd:\app\dump';
IMP_FULL_DATABASE
和DBA
角色,remap_schema=scott:sys
:将源schema—scott的所有对象 装载到目标schema—sys的目标方案中
实例:
将Scott的dept、emp表导入到SYSTEM方案中
D:\app>impdp "'sys/password@oracle as sysdba'" directory=dump_dir dumpfile=tab.dmp tables=scott.emp remap_schema=scott:sys
用户角色验证时,由于sys是dba用户,所以不能简单地用用户名和密码登陆
正确语法是:sys/password@oracle as sysdba
这样才不会出现以下报错:
DI-28009: 操作产生了 ORACLE 错误 28009
ORA-28009: connection as SYS should be as SYSDBA or SYSOPER
用户名:
UDI-00005: 读取输入值时出现意外的文件结尾。
即将 存放在转储文件中的一个或多个表空间中的所有对象装载到数据库中。
参数:tablespace
实例:
将tbsp_1表空间中的所有对象都导入到当前的数据库中
D:\app>impdp "'sys/password@oracle as sysdba'" directory=dump_dir dumpfile=tablespace.dmp tablespace=tbsp_1
即将 存放在转储文件中的所有数据库对象及相关数据装载到数据库中。
参数:full
实例:
从 fulldatabase.dmp 文件中导入全数据库
D:\app>impdp "'sys/password@oracle as sysdba'" directory=dump_dir dumpfile=fulldatabase.dmp full=y
IMPDP参数:
REMAP_SCHEMA
=SOURCE_SCHEMA:TARGET_SCHEMA
REMAP_TABLESPACE
=SOURCE_TABLESPACE:TARGET_TABLESPACE
SQLFILE
=[DIRECTORY_OBJECT:]FILE_NAME
TABLE_EXISTS_ACTION
={SKIP|APPEND|TRUNCATE|REPLACE}
TRANSPORT_DATAFILES
=DATAFILE_NAME
详情参照《EXCEL文件导入Oracle(python脚本导入)
》