1. DIRECTORY
指定转储文件和日志文件所在的目录
DIRECTORY=directory_object
 Directory_object用于指定目录对象名称.需要注意,目录对象是使用CREATE DIRECTORY语句建立的对象,而不是OS目录
Expdp scott/tiger DIRECTORY= DMP  DUMPFILE=a.dump
create or replace directory dmp
   as ‘d:/dmp’
expdp zftang/zftang@zftang directory=dmp dumpfile=test.dmp content=metadata_only
2. CONTENT
该选项用于指定要导出的内容.默认值为ALL
 CONTENT={ALL | DATA_ONLY | METADATA_ONLY}
当设置CONTENT为ALL时,将导出对象定义及其所有数据.为DATA_ONLY时,只导出对象数据,为METADATA_ONLY时,只导出对象定义
expdp zftang/zftang@zftang directory=dmp  dumpfile=test.dmp content=metadata_only
———-只导出对象定义
expdp zftang/zftang@zftang directory=dmp  dumpfile=test.dmp content=data_only
———-导出出所有数据
3. DUMPFILE
用于指定转储文件的名称,默认名称为expdat.dmp
 DUMPFILE=[directory_object:]file_name [,….]
Directory_object用于指定目录对象名,file_name用于指定转储文件名.需要注意,如果不指定directory_object,导出工具会自动使用DIRECTORY选项指定的目录对象
expdp zftang/zftang@zftang directory=dmp dumpfile=test1.dmp
数据泵工具导出的步骤:
 1、创建DIRECTORY
 create directory dir_dp as ‘D:/oracle/dir_dp’; 
 2、授权
Grant read,write target=”_blank”>zftang/zftang@fgisdb schemas=zftang directory=dir_dp dumpfile =expdp_test1.dmp logfile=expdp_test1.log;
连接到: Oracle Database 10g Enterprise Edition Release 10.2.0.1
 With the Partitioning, OLAP and Data Mining options
启动 "ZFTANG"."SYS_EXPORT_SCHEMA_01":  zftang/********@fgisdb sch
 ory=dir_dp dumpfile =expdp_test1.dmp logfile=expdp_test1.log;  */
备注:
   1、directory=dir_dp必须放在前面,如果将其放置最后,会提示 ORA-39002: 操作无效
                                                             ORA-39070: 无法打开日志文件。
                                                             ORA-39087: 目录名 DATA_PUMP_DIR; 无效
     
   2、在导出过程中,DATA DUMP 创建并使用了一个名为SYS_EXPORT_SCHEMA_01的对象,此对象就是DATA DUMP导出过程中所用的JOB名字,如果在执行这个命令时如果没有指定导出的JOB名字那么就会产生一个默认的JOB名字,如果在导出过程中指定JOB名字就为以指定名字出现
     如下改成:
     expdp zftang/zftang@fgisdb schemas=zftang directory=dir_dp dumpfile =expdp_test1.dmp logfile=expdp_test1.log,job_name=my_job1;
   3、导出语句后面不要有分号,否则如上的导出语句中的job表名为‘my_job1;’,而不是my_job1。因此导致expdp zftang/zftang attach=zftang.my_job1执行该命令时一直提示找不到job表
数据泵导出的各种模式:
1、 按表模式导出:
expdp zftang/zftang@fgisdb  tables=zftang.b$i_exch_info,zftang.b$i_manhole_info dumpfile =expdp_test2.dmp logfile=expdp_test2.log directory=dir_dp job_name=my_job
 2、按查询条件导出:
expdp zftang/zftang@fgisdb  tables=zftang.b$i_exch_info dumpfile =expdp_test3.dmp logfile=expdp_test3.log directory=dir_dp job_name=my_job query=’"where rownum<11"’
 3、按表空间导出:
Expdp zftang/zftang@fgisdb dumpfile=expdp_tablespace.dmp tablespaces=GCOMM.DBF logfile=expdp_tablespace.log directory=dir_dp job_name=my_job
 4、导出方案
Expdp zftang/zftang DIRECTORY=dir_dp DUMPFILE=schema.dmp SCHEMAS=zftang,gwm
 5、导出整个数据库:
expdp zftang/zftang@fgisdb dumpfile =full.dmp full=y logfile=full.log directory=dir_dp job_name=my_job
impdp导入模式:
 1、按表导入
p_street_area.dmp文件中的表,此文件是以gwm用户按schemas=gwm导出的:
impdp gwm/gwm@fgisdb  dumpfile =p_street_area.dmp logfile=imp_p_street_area.log directory=dir_dp tables=p_street_area job_name=my_job
 2、按用户导入(可以将用户信息直接导入,即如果用户信息不存在的情况下也可以直接导入)
impdp gwm/gwm@fgisdb schemas=gwm dumpfile =expdp_test.dmp logfile=expdp_test.log directory=dir_dp job_name=my_job
 3、不通过expdp的步骤生成dmp文件而直接导入的方法:
–从源数据库中向目标数据库导入表p_street_area
 impdp gwm/gwm directory=dir_dp NETWORK_LINK=igisdb tables=p_street_area logfile=p_street_area.log  job_name=my_job
 igisdb是目的数据库与源数据的链接名,dir_dp是目的数据库上的目录
4、更换表空间
  采用remap_tablespace参数 
   –导出gwm用户下的所有数据
expdp system/orcl directory=data_pump_dir dumpfile=gwm.dmp SCHEMAS=gwm
注:如果是用sys用户导出的用户数据,包括用户创建、授权部分,用自身用户导出则不含这些内容
–以下是将gwm用户下的数据全部导入到表空间gcomm(原来为gmapdata表空间下)下
impdp system/orcl directory=data_pump_dir dumpfile=gwm.dmp remap_tablespace=gmapdata:gcomm
数据泵是服务器端工具,导出的文件是放在数据库所在的服务器上,当然我们知道可以通过directory目录对象来控制。目录对象默认有四个级别,当然是有优先级顺序的,优先级从上往下
1.每个文件单独的指定具体的目录
2.expdp导出时,指定的目录参数
3.用户定义的环境变量DATA_PUMP_DIR指定的目录
4.默认的目录对象DATA_PUMP_DIR
当然了对于oracle11g R2来说,又引入了一个可选项,我们就当是5
5.DATA_PUMP_DIR_SCHEMA_NAME目录
 一、默认的目录对象DATA_PUMP_DIR测试
SQL>  desc dba_directories
  Name                                                              Null?    Type
  —————————————————————– ——– ———————- OWNER                                                             NOT NULL VARCHAR2(30)
  DIRECTORY_NAME                                                    NOT NULL VARCHAR2(30)
  DIRECTORY_PATH                                                             VARCHAR2(4000)
SQL> set linesize 120 pagesize 100
 SQL> col OWNER for a5    
 SQL> col DIRECTORY_NAME for a22
 SQL> col DIRECTORY_PATH for a80
 SQL> select * from dba_directories;
OWNER DIRECTORY_NAME         DIRECTORY_PATH
 —– ———————- ———————————————————-
SYS   SUBDIR                 /u01/app/oracle/product/11.2.0/db/demo/schema/order_entry//2002/Sep
 SYS   SS_OE_XMLDIR           /u01/app/oracle/product/11.2.0/db/demo/schema/order_entry/
 SYS   LOG_FILE_DIR           /u01/app/oracle/product/11.2.0/db/demo/schema/log/
 SYS   MEDIA_DIR              /u01/app/oracle/product/11.2.0/db/demo/schema/product_media/
 SYS   XMLDIR                 /u01/app/oracle/product/11.2.0/db/rdbms/xml
 SYS   DATA_FILE_DIR          /u01/app/oracle/product/11.2.0/db/demo/schema/sales_history/
 SYS   DATA_PUMP_DIR          /u01/app/oracle/admin/tj01/dpdump/
 SYS   ORACLE_OCM_CONFIG_DIR  /u01/app/oracle/product/11.2.0/db/ccr/state
通过查询我们看到,所有的目录都属于SYS用户,而不管是哪个用户创建的,在数据库里已经提前建好了这个目录对象DATA_PUMP_DIR。如果在使用expdp导出时,不指定目录对象参数,Oracle会使用数据库缺省的目录DATA_PUMP_DIR,不过如果想使用这个目录的话,用户需要具有exp_full_database的权限才行
SQL> conn scott/tiger
 Connected.
SQL> select * from tab;
 TNAME                          TABTYPE  CLUSTERID
 —————————— ——- ———-
 BONUS                          TABLE
 DEPT                           TABLE
 EMP                            TABLE
 SALGRADE                       TABLE
 SQL> create table demo as select empno,ename,sal,deptno from emp;
 Table created.
 SQL> exit          
 Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 – 64bit Production
 With the Partitioning, Automatic Storage Management, OLAP, Data Mining
 and Real Application Testing options
由于没有exp_full_database,所以这样的导出会报错,你可以选择授权或者使用有权限的用户
[oracle@asm11g ~]$ expdp scott/tiger dumpfile=emp.dmp tables=emp
 Export: Release 11.2.0.3.0 – Production on Fri Nov 16 13:48:19 2012
 Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.
 Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 – 64bit Production
 With the Partitioning, Automatic Storage Management, OLAP, Data Mining
 and Real Application Testing options
 ORA-39002: invalid operation
 ORA-39070: Unable to open the log file.
 ORA-39145: directory object parameter must be specified and non-null
 [oracle@asm11g ~]$ sqlplus / as sysdba
 SQL*Plus: Release 11.2.0.3.0 Production on Fri Nov 16 13:58:14 2012
 Copyright (c) 1982, 2011, Oracle.  All rights reserved.
 Connected to:
 Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 – 64bit Production
 With the Partitioning, Automatic Storage Management, OLAP, Data Mining
 and Real Application Testing options
SQL> grant exp_full_database to scott;
 Grant succeeded.
SQL> exit
 Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 – 64bit Production
 With the Partitioning, Automatic Storage Management, OLAP, Data Mining
 and Real Application Testing options
授权之后,导出成功,并且导出的文件和日志会到DATA_PUMP_DIR对象指定的目录
[oracle@asm11g ~]$ expdp scott/tiger dumpfile=emp.dmp tables=emp
Export: Release 11.2.0.3.0 – Production on Fri Nov 16 13:58:52 2012
 Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.
 Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 – 64bit Production
 With the Partitioning, Automatic Storage Management, OLAP, Data Mining
 and Real Application Testing options
 Starting "SCOTT"."SYS_EXPORT_TABLE_01":  scott/******** dumpfile=emp.dmp tables=emp
 Estimate in progress using BLOCKS method…
 Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
 Total estimation using BLOCKS method: 64 KB
 Processing object type TABLE_EXPORT/TABLE/TABLE
 Processing object type TABLE_EXPORT/TABLE/GRANT/OWNER_GRANT/OBJECT_GRANT
 Processing object type TABLE_EXPORT/TABLE/INDEX/INDEX
 Processing object type TABLE_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
 Processing object type TABLE_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
 Processing object type TABLE_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINT
 Processing object type TABLE_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
 . . exported "SCOTT"."EMP"                               8.562 KB      14 rows
 Master table "SCOTT"."SYS_EXPORT_TABLE_01" successfully loaded/unloaded
 ******************************************************************************
 Dump file set for SCOTT.SYS_EXPORT_TABLE_01 is:
   /u01/app/oracle/admin/tj01/dpdump/emp.dmp
Job "SCOTT"."SYS_EXPORT_TABLE_01" successfully completed at 13:59:05
对于oracle11g来说,我们还可以定义一个新的目录对象,对象名称是DATA_PUMP_DIR_SCHEMA_NAME,如果定义了这个目录对象,并授予权限,在用户导出没有指定
具体的目录参数的情况下,导出文件会到这个目录
[oracle@asm11g ~]$ mkdir sdir
 [oracle@asm11g ~]$ sqlplus / as sysdba
 SQL*Plus: Release 11.2.0.3.0 Production on Fri Nov 16 14:13:06 2012
 Copyright (c) 1982, 2011, Oracle.  All rights reserved.
Connected to:
 Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 – 64bit Production
 With the Partitioning, Automatic Storage Management, OLAP, Data Mining
 and Real Application Testing options
SQL> create directory data_pump_dir_scott as ‘/home/oracle/sdir’;
 Directory created.
SQL> grant read,write on  directory data_pump_dir_scott to scott;
 Grant succeeded.
SQL> exit
 Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 – 64bit Production
 With the Partitioning, Automatic Storage Management, OLAP, Data Mining
 and Real Application Testing options
[oracle@asm11g ~]$ expdp scott/tiger dumpfile=emp1.dmp tables=emp
Export: Release 11.2.0.3.0 – Production on Fri Nov 16 14:14:29 2012
Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 – 64bit Production
 With the Partitioning, Automatic Storage Management, OLAP, Data Mining
 and Real Application Testing options
 Database Directory Object has defaulted to: "DATA_PUMP_DIR_SCOTT".
 Starting "SCOTT"."SYS_EXPORT_TABLE_01":  scott/******** dumpfile=emp5.dmp tables=emp
 Estimate in progress using BLOCKS method…
 Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
 Total estimation using BLOCKS method: 64 KB
 Processing object type TABLE_EXPORT/TABLE/TABLE
 Processing object type TABLE_EXPORT/TABLE/GRANT/OWNER_GRANT/OBJECT_GRANT
 Processing object type TABLE_EXPORT/TABLE/INDEX/INDEX
 Processing object type TABLE_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
 Processing object type TABLE_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
 Processing object type TABLE_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINT
 Processing object type TABLE_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
 . . exported "SCOTT"."EMP"                               8.562 KB      14 rows
 Master table "SCOTT"."SYS_EXPORT_TABLE_01" successfully loaded/unloaded
 ******************************************************************************
 Dump file set for SCOTT.SYS_EXPORT_TABLE_01 is:
   /home/oracle/sdir/emp1.dmp
Job "SCOTT"."SYS_EXPORT_TABLE_01" successfully completed at 14:14:34
二、如果设定了环境变量DATA_PUMP_DIR的话,环境变量会覆盖缺省设置
[oracle@asm11g ~]$ mkdir udir
 [oracle@asm11g ~]$ sqlplus / as sysdba
 SQL*Plus: Release 11.2.0.3.0 Production on Fri Nov 16 13:59:15 2012
 Copyright (c) 1982, 2011, Oracle.  All rights reserved.
Connected to:
 Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 – 64bit Production
 With the Partitioning, Automatic Storage Management, OLAP, Data Mining
 and Real Application Testing options
SQL> create directory udir as ‘/home/oracle/udir’;
 Directory created.
SQL> grant write ,read on directory udir to scott;
 Grant succeeded.
SQL> exit
 Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 – 64bit Production
 With the Partitioning, Automatic Storage Management, OLAP, Data Mining
 and Real Application Testing options
注意,在定义环境变量的时候,后面的值要用大写
[oracle@asm11g ~]$ export DATA_PUMP_DIR=udir
 [oracle@asm11g ~]$ expdp scott/tiger dumpfile=emp2.dmp tables=emp
Export: Release 11.2.0.3.0 – Production on Fri Nov 16 14:05:07 2012
Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 – 64bit Production
 With the Partitioning, Automatic Storage Management, OLAP, Data Mining
 and Real Application Testing options
 ORA-39002: invalid operation
 ORA-39070: Unable to open the log file.
 ORA-39087: directory name udir is invalid
 [oracle@asm11g ~]$ export DATA_PUMP_DIR=UDIR
 [oracle@asm11g ~]$ expdp scott/tiger dumpfile=emp2.dmp tables=emp
 Export: Release 11.2.0.3.0 – Production on Fri Nov 16 14:05:23 2012
 Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 – 64bit Production
 With the Partitioning, Automatic Storage Management, OLAP, Data Mining
 and Real Application Testing options
 Database Directory Object has defaulted to: "UDIR".
 Starting "SCOTT"."SYS_EXPORT_TABLE_01":  scott/******** dumpfile=emp3.dmp tables=emp
 Estimate in progress using BLOCKS method…
 Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
 Total estimation using BLOCKS method: 64 KB
 Processing object type TABLE_EXPORT/TABLE/TABLE
 Processing object type TABLE_EXPORT/TABLE/GRANT/OWNER_GRANT/OBJECT_GRANT
 Processing object type TABLE_EXPORT/TABLE/INDEX/INDEX
 Processing object type TABLE_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
 Processing object type TABLE_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
 Processing object type TABLE_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINT
 Processing object type TABLE_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
 . . exported "SCOTT"."EMP"                               8.562 KB      14 rows
 Master table "SCOTT"."SYS_EXPORT_TABLE_01" successfully loaded/unloaded
 ******************************************************************************
 Dump file set for SCOTT.SYS_EXPORT_TABLE_01 is:
   /home/oracle/udir/emp2.dmp
Job "SCOTT"."SYS_EXPORT_TABLE_01" successfully completed at 14:05:29
三、如果导出时定义了参数directory,会使用参数指定的目录
[oracle@asm11g ~]$ expdp scott/tiger directory=udir tables=emp
Export: Release 11.2.0.3.0 – Production on Fri Nov 16 14:07:33 2012
 Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.
 Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 – 64bit Production
 With the Partitioning, Automatic Storage Management, OLAP, Data Mining
 and Real Application Testing options
 Starting "SCOTT"."SYS_EXPORT_TABLE_01":  scott/******** directory=udir tables=emp
 Estimate in progress using BLOCKS method…
 Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
 Total estimation using BLOCKS method: 64 KB
 Processing object type TABLE_EXPORT/TABLE/TABLE
 Processing object type TABLE_EXPORT/TABLE/GRANT/OWNER_GRANT/OBJECT_GRANT
 Processing object type TABLE_EXPORT/TABLE/INDEX/INDEX
 Processing object type TABLE_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
 Processing object type TABLE_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
 Processing object type TABLE_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINT
 Processing object type TABLE_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
 . . exported "SCOTT"."EMP"                               8.562 KB      14 rows
 Master table "SCOTT"."SYS_EXPORT_TABLE_01" successfully loaded/unloaded
 ******************************************************************************
 Dump file set for SCOTT.SYS_EXPORT_TABLE_01 is:
   /home/oracle/udir/expdat.dmp
Job "SCOTT"."SYS_EXPORT_TABLE_01" successfully completed at 14:07:41
四、如果每个文件都指定了具体的目录的话,会以文件定义的目录为准
[oracle@asm11g ~]$ mkdir userdir
 [oracle@asm11g ~]$ sqlplus / as sysdba
 SQL*Plus: Release 11.2.0.3.0 Production on Fri Nov 16 14:09:58 2012
 Copyright (c) 1982, 2011, Oracle.  All rights reserved.
 Connected to:
 Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 – 64bit Production
 With the Partitioning, Automatic Storage Management, OLAP, Data Mining
 and Real Application Testing options
SQL>  create or replace directory userdir as ‘/home/oracle/userdir’;
 Directory created.
SQL>  grant read,write on directory userdir to scott;
 Grant succeeded.
SQL> exit
 Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 – 64bit Production
 With the Partitioning, Automatic Storage Management, OLAP, Data Mining
 and Real Application Testing options
[oracle@asm11g ~]$ expdp scott/tiger dumpfile=userdir:emp3.dmp logfile=userdir:test.log tables=emp
Export: Release 11.2.0.3.0 – Production on Fri Nov 16 14:12:38 2012
 Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 – 64bit Production
 With the Partitioning, Automatic Storage Management, OLAP, Data Mining
 and Real Application Testing options
 Database Directory Object has defaulted to: "UDIR".
 Starting "SCOTT"."SYS_EXPORT_TABLE_01":  scott/******** dumpfile=userdir:emp4.dmp logfile=userdir:test.log tables=emp
 Estimate in progress using BLOCKS method…
 Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
 Total estimation using BLOCKS method: 64 KB
 Processing object type TABLE_EXPORT/TABLE/TABLE
 Processing object type TABLE_EXPORT/TABLE/GRANT/OWNER_GRANT/OBJECT_GRANT
 Processing object type TABLE_EXPORT/TABLE/INDEX/INDEX
 Processing object type TABLE_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
 Processing object type TABLE