16.1 EXPDP和IMPDP概述
16.2 EXPDP导出数据
EXPDP可以导出表,用户模式,表空间和全数据库
16.2.1 执行EXPDP命令
EXPDP是服务器端工具,只能在Oracle服务器端使用
使用EXPDP工具,必须首先建立DIRECTORY对象,并且需要为数据库用户授予使用DIRECTORY对象的权限。
SQL> create directory dump_dir as '/ora/dump';
Directory created.
SQL> grant read,write on directory dump_dir to scott;
Grant succeeded.

1、导出表
SQL> create or replace directory dump_dir as '/ora/dump';
Directory created.
SQL> grant read,write on directory dump_dir to scott;
Grant succeeded.
SQL> show user;
USER is "SYS"
SQL> select * from dba_directories;
OWNER DIRECTORY_NAME
------------------------------ ------------------------------
DIRECTORY_PATH
--------------------------------------------------------------------------------
SYS DUMP_DIR
/ora/dump

[oracle@localhost ~]$ mkdir /ora/dump
[oracle@localhost ~]$ ll /ora
总用量 40
drwxrwxr-x 4 oracle oinstall 4096 11月 17 20:48 app
drwxrwxr-x 2 oracle oinstall 4096 1月 8 14:57 backup
drwxrwxr-x. 8 oracle oinstall 4096 8月 21 2009 database
drwxr-xr-x 2 oracle oinstall 4096 1月 9 16:08 dump
drwxrwxr-x 2 oracle oinstall 16384 11月 17 19:43 lost+found
drwxrwxr-x 3 oracle oinstall 4096 11月 17 22:06 oracle
drwxrwxr-x 10 oracle oinstall 4096 1月 9 15:46 oratemp

[oracle@localhost ~]$ expdp scott/123456 directory=dump_dir dumpfile=tab.dmp tables=emp,dept
Export: Release 11.2.0.1.0 - Production on Thu Jan 9 16:08:53 2014
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Starting "SCOTT"."SYS_EXPORT_TABLE_01": scott/******** directory=dump_dir dumpfile=tab.dmp tables=emp,dept
Estimate in progress using BLOCKS method...
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 128 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/INDEX/FUNCTIONAL_AND_BITMAP/INDEX
Processing object type TABLE_EXPORT/TABLE/INDEX/STATISTICS/FUNCTIONAL_AND_BITMAP/INDEX_STATISTICS
Processing object type TABLE_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
. . exported "SCOTT"."DEPT" 5.960 KB 5 rows
. . exported "SCOTT"."EMP" 9.007 KB 15 rows
Master table "SCOTT"."SYS_EXPORT_TABLE_01" successfully loaded/unloaded
******************************************************************************
Dump file set for SCOTT.SYS_EXPORT_TABLE_01 is:
  /ora/dump/tab.dmp
Job "SCOTT"."SYS_EXPORT_TABLE_01" successfully completed at 16:09:16

2、导出模式
用户必须具有DBA角色或EXP_FULL_DATABASE角色
[oracle@localhost ~]$ expdp system/123456 directory=dump_dir dumpfile=schema.dmp schemas=scott
Export: Release 11.2.0.1.0 - Production on Thu Jan 9 16:13:42 2014
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Starting "SYSTEM"."SYS_EXPORT_SCHEMA_01": system/******** directory=dump_dir dumpfile=schema.dmp schemas=scott
Estimate in progress using BLOCKS method...
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 448 KB
Processing object type SCHEMA_EXPORT/USER
Processing object type SCHEMA_EXPORT/SYSTEM_GRANT
Processing object type SCHEMA_EXPORT/ROLE_GRANT
Processing object type SCHEMA_EXPORT/DEFAULT_ROLE
Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
Processing object type SCHEMA_EXPORT/TABLE/TABLE
Processing object type SCHEMA_EXPORT/TABLE/GRANT/OWNER_GRANT/OBJECT_GRANT
Processing object type SCHEMA_EXPORT/TABLE/INDEX/INDEX
Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
Processing object type SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
Processing object type SCHEMA_EXPORT/VIEW/VIEW
Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINT
Processing object type SCHEMA_EXPORT/TABLE/INDEX/FUNCTIONAL_AND_BITMAP/INDEX
Processing object type SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/FUNCTIONAL_AND_BITMAP/INDEX_STATISTICS
Processing object type SCHEMA_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
. . exported "SCOTT"."STUDENTS_3" 8.695 KB 2 rows
. . exported "SCOTT"."DEPT" 5.960 KB 5 rows
. . exported "SCOTT"."EMP" 9.007 KB 15 rows
. . exported "SCOTT"."SALGRADE" 5.867 KB 5 rows
. . exported "SCOTT"."BONUS" 0 KB 0 rows
. . exported "SCOTT"."DEPT_TEMP" 0 KB 0 rows
. . exported "SCOTT"."EMP_TEMP" 0 KB 0 rows
. . exported "SCOTT"."STUDENT" 0 KB 0 rows
. . exported "SCOTT"."STUDENTS" 0 KB 0 rows
. . exported "SCOTT"."STUDENTS_1" 0 KB 0 rows
Master table "SYSTEM"."SYS_EXPORT_SCHEMA_01" successfully loaded/unloaded
******************************************************************************
Dump file set for SYSTEM.SYS_EXPORT_SCHEMA_01 is:
  /ora/dump/schema.dmp
Job "SYSTEM"."SYS_EXPORT_SCHEMA_01" successfully completed at 16:15:05

3、导出表空间
用户必须具有DBA角色或EXP_FULL_DATABASE角色
[oracle@localhost ~]$ expdp system/123456 directory=dump_dir dumpfile=ts_1.dmp tablespaces=ts_1
Export: Release 11.2.0.1.0 - Production on Fri Jan 10 10:17:16 2014
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
ORA-31626: job does not exist
ORA-31633: unable to create master table "SYSTEM.SYS_EXPORT_TABLESPACE_05"
ORA-06512: at "SYS.DBMS_SYS_ERROR", line 95
ORA-06512: at "SYS.KUPV$FT", line 1020
ORA-01658: unable to create INITIAL extent for segment in tablespace TBS_TEST_1

SQL> alter tablespace TBS_TEST_1  resize 100M;
alter tablespace TBS_TEST_1  resize 100M
*
ERROR at line 1:
ORA-32773: operation not supported for smallfile tablespace TBS_TEST_1
SQL> select file_id,tablespace_name from dba_data_files;
   FILE_ID TABLESPACE_NAME
---------- ------------------------------
         4 USERS
         3 UNDOTBS1
         2 SYSAUX
         1 SYSTEM
         5 EXAMPLE
         6 TBS_TEST_1
         7 TBS_TEST_2
         8 TBS_TEST_3
         9 TBS_TEST_4
        11 TBS_BIG
        10 TS_1
   FILE_ID TABLESPACE_NAME
---------- ------------------------------
        12 TS_2
        13 TS_3
        14 RMAN_TBSP
14 rows selected.
SQL> alter database datafile 6 resize 100m;
Database altered.

[oracle@localhost ~]$ expdp system/123456 directory=dump_dir dumpfile=ts_1.dmp tablespaces=ts_1
Export: Release 11.2.0.1.0 - Production on Fri Jan 10 11:31:31 2014
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Starting "SYSTEM"."SYS_EXPORT_TABLESPACE_01": system/******** directory=dump_dir dumpfile=ts_1.dmp tablespaces=ts_1
Estimate in progress using BLOCKS method...
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 0 KB
ORA-31655: no data or metadata objects selected for job
Job "SYSTEM"."SYS_EXPORT_TABLESPACE_01" completed with 1 error(s) at 11:31:48




[oracle@localhost ~]$ expdp system/123456 directory=dump_dir dumpfile=tablespace.dmp tablespaces=users
Export: Release 11.2.0.1.0 - Production on Thu Jan 9 16:19:00 2014
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Starting "SYSTEM"."SYS_EXPORT_TABLESPACE_01": system/******** directory=dump_dir dumpfile=tablespace.dmp tablespaces=users
Estimate in progress using BLOCKS method...
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 1024 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/INDEX/FUNCTIONAL_AND_BITMAP/INDEX
Processing object type TABLE_EXPORT/TABLE/INDEX/STATISTICS/FUNCTIONAL_AND_BITMAP/INDEX_STATISTICS
Processing object type TABLE_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
. . exported "OE"."PURCHASEORDER" 243.9 KB 132 rows
. . exported "HR"."JOBS_TEMP" 6.328 KB 1 rows
. . exported "OE"."SUBCATEGORY_REF_LIST_NESTEDTAB" 6.585 KB 21 rows
. . exported "OE"."PRODUCT_REF_LIST_NESTEDTAB" 12.50 KB 288 rows
. . exported "OE"."CATEGORIES_TAB" 14.15 KB 22 rows
. . exported "SCOTT"."DEPT" 5.960 KB 5 rows
. . exported "SCOTT"."EMP" 9.007 KB 15 rows
. . exported "SCOTT"."SALGRADE" 5.867 KB 5 rows
. . exported "SCOTT"."BONUS" 0 KB 0 rows
. . exported "SH"."DIMENSION_EXCEPTIONS" 0 KB 0 rows
. . exported "XIFANG"."TB_XIFANG" 0 KB 0 rows
. . exported "XIFANG"."TB_XIFANG_2" 0 KB 0 rows
Master table "SYSTEM"."SYS_EXPORT_TABLESPACE_01" successfully loaded/unloaded
******************************************************************************
Dump file set for SYSTEM.SYS_EXPORT_TABLESPACE_01 is:
  /ora/dump/tablespace.dmp
Job "SYSTEM"."SYS_EXPORT_TABLESPACE_01" successfully completed at 16:19:34

4、导出全数据库
用户必须具有DBA角色或EXP_FULL_DATABASE角色
[oracle@localhost ~]$ expdp system/123456 directory=dump_dir dumpfile=fulldatabase.dmp full=y
Export: Release 11.2.0.1.0 - Production on Thu Jan 9 16:20:57 2014
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Starting "SYSTEM"."SYS_EXPORT_FULL_01": system/******** directory=dump_dir dumpfile=fulldatabase.dmp full=y
Estimate in progress using BLOCKS method...
Processing object type DATABASE_EXPORT/SCHEMA/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 121.7 MB
Processing object type DATABASE_EXPORT/TABLESPACE
Processing object type DATABASE_EXPORT/PROFILE
Processing object type DATABASE_EXPORT/SYS_USER/USER
Processing object type DATABASE_EXPORT/SCHEMA/USER
Processing object type DATABASE_EXPORT/ROLE
Processing object type DATABASE_EXPORT/GRANT/SYSTEM_GRANT/PROC_SYSTEM_GRANT
Processing object type DATABASE_EXPORT/SCHEMA/GRANT/SYSTEM_GRANT
Processing object type DATABASE_EXPORT/SCHEMA/ROLE_GRANT
Processing object type DATABASE_EXPORT/SCHEMA/DEFAULT_ROLE
Processing object type DATABASE_EXPORT/SCHEMA/TABLESPACE_QUOTA
Processing object type DATABASE_EXPORT/RESOURCE_COST
Processing object type DATABASE_EXPORT/TRUSTED_DB_LINK
Processing object type DATABASE_EXPORT/SCHEMA/SEQUENCE/SEQUENCE
Processing object type DATABASE_EXPORT/SCHEMA/SEQUENCE/GRANT/OWNER_GRANT/OBJECT_GRANT
Processing object type DATABASE_EXPORT/DIRECTORY/DIRECTORY
Processing object type DATABASE_EXPORT/DIRECTORY/GRANT/OWNER_GRANT/OBJECT_GRANT
Processing object type DATABASE_EXPORT/CONTEXT
Processing object type DATABASE_EXPORT/SCHEMA/PUBLIC_SYNONYM/SYNONYM
Processing object type DATABASE_EXPORT/SCHEMA/SYNONYM
Processing object type DATABASE_EXPORT/SCHEMA/TYPE/INC_TYPE
Processing object type DATABASE_EXPORT/SCHEMA/TYPE/TYPE_SPEC
Processing object type DATABASE_EXPORT/SCHEMA/TYPE/GRANT/OWNER_GRANT/OBJECT_GRANT
Processing object type DATABASE_EXPORT/SYSTEM_PROCOBJACT/PRE_SYSTEM_ACTIONS/PROCACT_SYSTEM
Processing object type DATABASE_EXPORT/SYSTEM_PROCOBJACT/PROCOBJ
Processing object type DATABASE_EXPORT/SYSTEM_PROCOBJACT/POST_SYSTEM_ACTIONS/PROCACT_SYSTEM
Processing object type DATABASE_EXPORT/SCHEMA/PROCACT_SCHEMA
Processing object type DATABASE_EXPORT/SCHEMA/XMLSCHEMA/XMLSCHEMA
Processing object type DATABASE_EXPORT/SCHEMA/TABLE/TABLE
Processing object type DATABASE_EXPORT/SCHEMA/TABLE/PRE_TABLE_ACTION
Processing object type DATABASE_EXPORT/SCHEMA/TABLE/GRANT/OWNER_GRANT/OBJECT_GRANT
Processing object type DATABASE_EXPORT/SCHEMA/TABLE/INDEX/INDEX
Processing object type DATABASE_EXPORT/SCHEMA/TABLE/CONSTRAINT/CONSTRAINT
Processing object type DATABASE_EXPORT/SCHEMA/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
Processing object type DATABASE_EXPORT/SCHEMA/TABLE/COMMENT
Processing object type DATABASE_EXPORT/SCHEMA/PACKAGE/PACKAGE_SPEC
Processing object type DATABASE_EXPORT/SCHEMA/PACKAGE/GRANT/OWNER_GRANT/OBJECT_GRANT
Processing object type DATABASE_EXPORT/SCHEMA/FUNCTION/FUNCTION
Processing object type DATABASE_EXPORT/SCHEMA/FUNCTION/GRANT/OWNER_GRANT/OBJECT_GRANT
Processing object type DATABASE_EXPORT/SCHEMA/PROCEDURE/PROCEDURE
Processing object type DATABASE_EXPORT/SCHEMA/PROCEDURE/GRANT/OWNER_GRANT/OBJECT_GRANT
Processing object type DATABASE_EXPORT/SCHEMA/PACKAGE/COMPILE_PACKAGE/PACKAGE_SPEC/ALTER_PACKAGE_SPEC
Processing object type DATABASE_EXPORT/SCHEMA/FUNCTION/ALTER_FUNCTION
Processing object type DATABASE_EXPORT/SCHEMA/PROCEDURE/ALTER_PROCEDURE
Processing object type DATABASE_EXPORT/SCHEMA/VIEW/VIEW
Processing object type DATABASE_EXPORT/SCHEMA/VIEW/GRANT/OWNER_GRANT/OBJECT_GRANT
Processing object type DATABASE_EXPORT/SCHEMA/VIEW/COMMENT
Processing object type DATABASE_EXPORT/SCHEMA/TABLE/CONSTRAINT/REF_CONSTRAINT
Processing object type DATABASE_EXPORT/SCHEMA/PACKAGE_BODIES/PACKAGE/PACKAGE_BODY
Processing object type DATABASE_EXPORT/SCHEMA/TYPE/TYPE_BODY
Processing object type DATABASE_EXPORT/SCHEMA/TABLE/INDEX/FUNCTIONAL_AND_BITMAP/INDEX
Processing object type DATABASE_EXPORT/SCHEMA/TABLE/INDEX/STATISTICS/FUNCTIONAL_AND_BITMAP/INDEX_STATISTICS
Processing object type DATABASE_EXPORT/SCHEMA/TABLE/STATISTICS/TABLE_STATISTICS
Processing object type DATABASE_EXPORT/SCHEMA/TABLE/INDEX/DOMAIN_INDEX/INDEX
Processing object type DATABASE_EXPORT/SCHEMA/TABLE/POST_TABLE_ACTION
Processing object type DATABASE_EXPORT/SCHEMA/TABLE/TRIGGER
Processing object type DATABASE_EXPORT/SCHEMA/VIEW/TRIGGER
Processing object type DATABASE_EXPORT/SCHEMA/EVENT/TRIGGER
Processing object type DATABASE_EXPORT/SCHEMA/MATERIALIZED_VIEW
Processing object type DATABASE_EXPORT/SCHEMA/JOB
Processing object type DATABASE_EXPORT/SCHEMA/DIMENSION
Processing object type DATABASE_EXPORT/SCHEMA/TABLE/POST_INSTANCE/PROCACT_INSTANCE
Processing object type DATABASE_EXPORT/SCHEMA/TABLE/POST_INSTANCE/PROCDEPOBJ
Processing object type DATABASE_EXPORT/SCHEMA/POST_SCHEMA/PROCOBJ
Processing object type DATABASE_EXPORT/SCHEMA/POST_SCHEMA/PROCACT_SCHEMA
Processing object type DATABASE_EXPORT/AUDIT
. . exported "SH"."CUSTOMERS" 9.853 MB 55500 rows
。。。
Master table "SYSTEM"."SYS_EXPORT_FULL_01" successfully loaded/unloaded
******************************************************************************
Dump file set for SYSTEM.SYS_EXPORT_FULL_01 is:
  /ora/dump/fulldatabase.dmp
Job "SYSTEM"."SYS_EXPORT_FULL_01" successfully completed at 16:33:18

16.2.2 EXPDP命令参数
1、directory 指定转储文件和日志文件所在的目录
2、dumpfile 指定转储文件的名称
3、tables 指定导出的表
4、schemas 指定导出的模式
5、tablespace 指定导出的表空间
6、full 指定数据库导出方式,默认为n,如果认为y,表示执行数据库导出
7、logfile 指定导出的日志文件的名称,默认名称为export.log
8、status 显示导出作业进程的详细状态,默认0,指定为n后,每隔n秒显示作业完成的百分比
9、content 指定要导出的内容,默认为all,content={all|data_only|metadata_only}
all:将导出对象数据和对象定义
data_only:导出对象数据
metadata_only:导出对象定义
10、query 指定过滤导出数据的where条件,语法如下:
query=[schema.][table_name:] query_clause

16.3 IMPDP导入数据
16.3.1 执行IMPDP命令
1、导入表
[oracle@localhost ~]$ impdp system/123456 directory=dump_dir dumpfile=tab.dmp tables=scott.dept remap_schema=scott:system
Import: Release 11.2.0.1.0 - Production on Thu Jan 9 16:58:03 2014
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Master table "SYSTEM"."SYS_IMPORT_TABLE_01" successfully loaded/unloaded
Starting "SYSTEM"."SYS_IMPORT_TABLE_01": system/******** directory=dump_dir dumpfile=tab.dmp tables=scott.dept remap_schema=scott:system
Processing object type TABLE_EXPORT/TABLE/TABLE
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
. . imported "SYSTEM"."DEPT" 5.960 KB 5 rows
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/STATISTICS/TABLE_STATISTICS
Job "SYSTEM"."SYS_IMPORT_TABLE_01" successfully completed at 16:58:19

2、导入模式
[oracle@localhost ~]$ impdp system/123456 directory=dump_dir dumpfile=schema.dmp schemas=scott remap_schema=scott:system
Import: Release 11.2.0.1.0 - Production on Thu Jan 9 17:00:08 2014
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Master table "SYSTEM"."SYS_IMPORT_SCHEMA_01" successfully loaded/unloaded
Starting "SYSTEM"."SYS_IMPORT_SCHEMA_01": system/******** directory=dump_dir dumpfile=schema.dmp schemas=scott remap_schema=scott:system
Processing object type SCHEMA_EXPORT/USER
Processing object type SCHEMA_EXPORT/SYSTEM_GRANT
Processing object type SCHEMA_EXPORT/ROLE_GRANT
Processing object type SCHEMA_EXPORT/DEFAULT_ROLE
Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
Processing object type SCHEMA_EXPORT/TABLE/TABLE
ORA-39151: Table "SYSTEM"."DEPT" exists. All dependent metadata and data will be skipped due to table_exists_action of skip
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
. . imported "SYSTEM"."STUDENTS_3" 8.695 KB 2 rows
. . imported "SYSTEM"."EMP" 9.007 KB 15 rows
. . imported "SYSTEM"."SALGRADE" 5.867 KB 5 rows
. . imported "SYSTEM"."BONUS" 0 KB 0 rows
. . imported "SYSTEM"."DEPT_TEMP" 0 KB 0 rows
. . imported "SYSTEM"."EMP_TEMP" 0 KB 0 rows
. . imported "SYSTEM"."STUDENT" 0 KB 0 rows
. . imported "SYSTEM"."STUDENTS" 0 KB 0 rows
. . imported "SYSTEM"."STUDENTS_1" 0 KB 0 rows
Processing object type SCHEMA_EXPORT/TABLE/GRANT/OWNER_GRANT/OBJECT_GRANT
Processing object type SCHEMA_EXPORT/TABLE/INDEX/INDEX
Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
Processing object type SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
Processing object type SCHEMA_EXPORT/VIEW/VIEW
Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINT
Processing object type SCHEMA_EXPORT/TABLE/INDEX/FUNCTIONAL_AND_BITMAP/INDEX
Processing object type SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/FUNCTIONAL_AND_BITMAP/INDEX_STATISTICS
Processing object type SCHEMA_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
Job "SYSTEM"."SYS_IMPORT_SCHEMA_01" completed with 1 error(s) at 17:00:25

3、导入表空间
[oracle@localhost ~]$ impdp system/123456 directory=dump_dir dumpfile=ts_1.dmp tablespaces=users
Import: Release 11.2.0.1.0 - Production on Fri Jan 10 14:54:39 2014
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Master table "SYSTEM"."SYS_IMPORT_TABLESPACE_02" successfully loaded/unloaded
Starting "SYSTEM"."SYS_IMPORT_TABLESPACE_02": system/******** directory=dump_dir dumpfile=ts_1.dmp tablespaces=users
Processing object type TABLE_EXPORT/TABLE/TABLE
ORA-39151: Table "SCOTT"."DEPT" exists. All dependent metadata and data will be skipped due to table_exists_action of skip
ORA-39151: Table "SCOTT"."EMP" exists. All dependent metadata and data will be skipped due to table_exists_action of skip
ORA-39151: Table "SCOTT"."BONUS" exists. All dependent metadata and data will be skipped due to table_exists_action of skip
ORA-39151: Table "SCOTT"."SALGRADE" exists. All dependent metadata and data will be skipped due to table_exists_action of skip
ORA-39151: Table "SH"."DIMENSION_EXCEPTIONS" exists. All dependent metadata and data will be skipped due to table_exists_action of skip
ORA-39151: Table "HR"."JOBS_TEMP" exists. All dependent metadata and data will be skipped due to table_exists_action of skip
ORA-39151: Table "XIFANG"."TB_XIFANG" exists. All dependent metadata and data will be skipped due to table_exists_action of skip
ORA-39151: Table "XIFANG"."TB_XIFANG_2" exists. All dependent metadata and data will be skipped due to table_exists_action of skip
ORA-39151: Table "SYSTEM"."DEPT" exists. All dependent metadata and data will be skipped due to table_exists_action of skip
ORA-39151: Table "SYSTEM"."EMP" exists. All dependent metadata and data will be skipped due to table_exists_action of skip
ORA-39151: Table "SYSTEM"."BONUS" exists. All dependent metadata and data will be skipped due to table_exists_action of skip
ORA-39151: Table "SYSTEM"."SALGRADE" exists. All dependent metadata and data will be skipped due to table_exists_action of skip
ORA-39151: Table "OE"."PURCHASEORDER" exists. All dependent metadata and data will be skipped due to table_exists_action of skip
ORA-39151: Table "OE"."CATEGORIES_TAB" exists. All dependent metadata and data will be skipped due to table_exists_action of skip
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
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/INDEX/FUNCTIONAL_AND_BITMAP/INDEX
Processing object type TABLE_EXPORT/TABLE/INDEX/STATISTICS/FUNCTIONAL_AND_BITMAP/INDEX_STATISTICS
Processing object type TABLE_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
Job "SYSTEM"."SYS_IMPORT_TABLESPACE_02" completed with 14 error(s) at 14:54:49

4、导入全数据库
[oracle@localhost ~]$ impdp system/123456 directory=dump_dir dumpfile=fulldatabase.dmp full=y

16.3.2 IMPDP命令参数
1、remap_schema
将源模式中的对象转存到目标模式中,语法如下:
remap_schema=source_schema:target_schema
2、remap_tablespace
导入是更改表空间名称
指定导入时表空间的名称,语法如下:
remap_tablespace=source_tablespace:target_tablespace
3、SQLFILE
从dmp文件中提取对象的DDL语句,语法如下:
sqlfile=[directory_object:]file_name
file_name表示包含DDL语句的文件
[oracle@localhost ~]$ impdp system/123456 directory=dump_dir dumpfile=tab.dump sqlfile=test.sql
Import: Release 11.2.0.1.0 - Production on Fri Jan 10 15:10:55 2014
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
ORA-39001: invalid argument value
ORA-39000: bad dump file specification
ORA-31640: unable to open dump file "/ora/dump/tab.dump" for read
ORA-27037: unable to obtain file status
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3

4、TABLE_EXISTS_ACTION 
指定当表已经存在时导入要执行的操作,语法如下:
table_exists_action={skip|append|truncate|replace}
默认为skip
5、TRANSPORT_DATAFILES
指定导入到目标数据库的数据文件、语法如下:
transport_datafiles=datafile_name
[oracle@localhost ~]$ impdp system/123456 directory=dump dumpfile=tran_datafile.dmp transport_datafiles='/ora/app/oracle/oradata/stone1/ts1.dbf'
Import: Release 11.2.0.1.0 - Production on Fri Jan 10 15:18:00 2014
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
ORA-39002: invalid operation
ORA-39070: Unable to open the log file.
ORA-39087: directory name DUMP is invalid

16.4 SQL*Loader工具
16.4.1 SQL*Loader概述
16.4.2 加载数据
1、自由格式加载
(1)创建一个表,存储要加载的数据
SQL> create table student1(
  2 stuno number(8),
  3 stuname varchar2(20),
  4 sex varchar2(8),
  5 old number(8)
  6 );

SQL> desc student1;
 Name Null? Type
 ----------------------------------------- -------- ----------------------------
 STUNO NUMBER(8)
 STUNAME VARCHAR2(20)
 SEX VARCHAR2(8)
 OLD NUMBER(8)

Table created.

(2)制作一份文件数据
[oracle@localhost ~]$ cat student1.txt
1001 east ma 30
1002 west fe 25
1003 jack ma 23
1004 rose fe 20
(3)编辑控制文件
[oracle@localhost ~]$ cat student1.ctl
load data
  infile '/home/oracle/student1.txt'
  into table student1
  (stuno position(01:04) integer external,
   stuname position(06:09) char,
   sex position(11:12) char,
   old position(14:15) integer external
  )

(4)调用SQL*Loader加载数据
[oracle@localhost ~]$ sqlldr scott/123456 control=/home/oracle/student1.ctl log=/home/oracle/student1.log
SQL*Loader: Release 11.2.0.1.0 - Production on Fri Jan 10 18:06:06 2014
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
Commit point reached - logical record count 4

(5)查看结果
SQL> select * from student1;
     STUNO STUNAME SEX OLD
---------- -------------------- -------- ----------
      1001 east ma 30
      1002 west fe 25
      1003 jack ma 23
      1004 rose fe 20

2、固定格式加载数据
(1)创建CSV文件
[oracle@localhost ~]$ cat persons.csv
1005,east,,26
1006,west,,25
1007,happy,,24
1008,mary,,20
(2)创建表
SQL> create table persons
  2 (code number(4),
  3 name varchar2(20),
  4 sex varchar2(4),
  5 old number(4)
  6 );
Table created.
(3)编辑控制文件
[oracle@localhost ~]$ cat persons.ctl
load data
infile '/home/oracle/persons.csv'
append into table persons
fields terminated by ','
(code,name,sex,old TERMINATED BY WHITESPACE)
(4)调用SQL*Loader加载数据
[oracle@localhost ~]$ sqlldr scott/123456 control=/home/oracle/persons.ctl
SQL*Loader: Release 11.2.0.1.0 - Production on Fri Jan 10 18:32:25 2014
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
Commit point reached - logical record count 4
(5)查看结果
SQL> select * from persons;
      CODE NAME SEX OLD
---------- -------------------- ---- ----------
      1005 east  26
      1006 west  25
      1007 happy  24
      1008 mary  20