search
HomeDatabaseMysql TutorialOracle数据泵的使用

http://hi.baidu.com/hanbingxiaoshi/item/63724f51aad754968c12edae 1、连接Oracle数据库 SQL conn / as sysdba 已连接。 2、创建一个操作目录 SQL create directory dump_dir as 'e:\dump'; 注意同时需要使用操作系统命令在硬盘上创建这个物理目录。 目录


http://hi.baidu.com/hanbingxiaoshi/item/63724f51aad754968c12edae


1、连接Oracle数据库
SQL> conn / as sysdba
已连接。

2、创建一个操作目录
SQL> create directory dump_dir as 'e:\dump';

注意同时需要使用操作系统命令在硬盘上创建这个物理目录。

目录已创建。

3、使用以下命令创建一个导出文件目录
SQL> grant read,write on directory dump_dir to scott;

授权成功。

4、使用命令expdp导出数据


C:\>expdp scott/tiger directory=dump_dir dumpfile=20080601.dmp tables=dept,emp

Export: Release 10.2.0.1.0 - Production on 星期三, 18 6月, 2008 15:49:00

Copyright (c) 2003, 2005, Oracle. All rights reserved.

连接到: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
启动 "SCOTT"."SYS_EXPORT_TABLE_01": scott/******** directory=dump_dir dumpfile=20080601.dmp table
dept,emp
正在使用 BLOCKS 方法进行估计...
处理对象类型 TABLE_EXPORT/TABLE/TABLE_DATA
使用 BLOCKS 方法的总估计: 128 KB
处理对象类型 TABLE_EXPORT/TABLE/TABLE
处理对象类型 TABLE_EXPORT/TABLE/INDEX/INDEX
处理对象类型 TABLE_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
处理对象类型 TABLE_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINT
. . 导出了 "SCOTT"."DEPT"                              5.656 KB       4 行
. . 导出了 "SCOTT"."EMP"                               7.820 KB      14 行
已成功加载/卸载了主表 "SCOTT"."SYS_EXPORT_TABLE_01"
******************************************************************************
SCOTT.SYS_EXPORT_TABLE_01 的转储文件集为:
E:\DUMP\20080601.DMP
作业 "SCOTT"."SYS_EXPORT_TABLE_01" 已于 15:49:22 成功完成


C:\>

**************************************************************************************************************
常见错误

如果没有在指定的硬盘上建立物理文件 ,则会出现如下错误提示信息:
解决的方法是现在硬盘上创建指定的物理文件目录,然后在执行expdp程序。
Oracle 中的 create directory dump_dir as 'e:\dump';
命令只是在逻辑上创建了一个Oracle能够识别的目录和硬盘上的一个物理目录之间的联系,
并不能真正的在硬盘上创建物理目录。

**************************************************************************************************************
C:\>expdp scott/tiger directory=dump_dir dumpfile=20080601.dmp tables=dept,emp

Export: Release 10.2.0.1.0 - Production on 星期三, 18 6月, 2008 15:46:19

Copyright (c) 2003, 2005, Oracle. All rights reserved.

连接到: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
ORA-39002: 操作无效
ORA-39070: 无法打开日志文件。
ORA-29283: 文件操作无效
ORA-06512: 在 "SYS.UTL_FILE", line 475
ORA-29283: 文件操作无效


导入命令:

impdp scott/tiger directory=dump_dir dumpfile=20080601.dmp tables=dept,emp

C:\>impdp scott/tiger directory=dump_dir dumpfile=20080601.dmp tables=dept,emp

Import: Release 10.2.0.1.0 - Production on 星期三, 18 6月, 2008 15:56:11

Copyright (c) 2003, 2005, Oracle. All rights reserved.

连接到: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
已成功加载/卸载了主表 "SCOTT"."SYS_IMPORT_TABLE_01"
启动 "SCOTT"."SYS_IMPORT_TABLE_01": scott/******** directory=dump_dir dumpfile=20080601.dmp table
dept,emp
处理对象类型 TABLE_EXPORT/TABLE/TABLE
处理对象类型 TABLE_EXPORT/TABLE/TABLE_DATA
. . 导入了 "SCOTT"."DEPT"                              5.656 KB       4 行
. . 导入了 "SCOTT"."EMP"                               7.820 KB      14 行
处理对象类型 TABLE_EXPORT/TABLE/INDEX/INDEX
处理对象类型 TABLE_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
处理对象类型 TABLE_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINT
作业 "SCOTT"."SYS_IMPORT_TABLE_01" 已于 15:56:20 成功完成

C:\>

查看结果,发现删除的数据表又已经找回来了:
SQL> set linesize 150;
SQL> select * from scott.emp;

     EMPNO ENAME      JOB              MGR HIREDATE              SAL       COMM     DEPTNO
---------- ---------- --------- ---------- -------------- ---------- ---------- ----------
      7369 SMITH      CLERK           7902 17-12月-80            800                    20
      7499 ALLEN      SALESMAN        7698 20-2月 -81           1600        300         30
      7521 WARD       SALESMAN        7698 22-2月 -81           1250        500         30
      7566 JONES      MANAGER         7839 02-4月 -81           2975                    20
      7654 MARTIN     SALESMAN        7698 28-9月 -81           1250       1400         30
      7698 BLAKE      MANAGER         7839 01-5月 -81           2850                    30
      7782 CLARK      MANAGER         7839 09-6月 -81           2450                    10
      7788 SCOTT      ANALYST         7566 19-4月 -87           3000                    20
      7839 KING       PRESIDENT            17-11月-81           5000                    10
      7844 TURNER     SALESMAN        7698 08-9月 -81           1500          0         30
      7876 ADAMS      CLERK           7788 23-5月 -87           1100                    20

     EMPNO ENAME      JOB              MGR HIREDATE              SAL       COMM     DEPTNO
---------- ---------- --------- ---------- -------------- ---------- ---------- ----------
      7900 JAMES      CLERK           7698 03-12月-81            950                    30
      7902 FORD       ANALYST         7566 03-12月-81           3000                    20
      7934 MILLER     CLERK           7782 23-1月 -82           1300                    10

已选择14行。

SQL> select * from scott.dept;

    DEPTNO DNAME          LOC
---------- -------------- -------------
        10 ACCOUNTING     NEW YORK
        20 RESEARCH       DALLAS
        30 SALES          CHICAGO
        40 OPERATIONS     BOSTON

SQL>


*******************************************************************************************************************************************
对Oracle10g中的数据泵导出数据的分析
*******************************************************************************************************************************************
Oracle10g中的数据泵只能用于服务器端,而不能用于客户端,它可以导出表、方案、表空间和整个数据库。


1、导出表
C:\>expdp scott/tiger directory=dump_dir dumpfile=20080601.dmp tables=dept,emp

2、导出方案
导出方案将方案的所有数据库对象和数据库表导出到一个文件中。

C:\>expdp hr/hr directory=dump_dir dumpfile=20080601schema.dmp schemas=hr
C:\>expdp hr/hr directory=dump_dir dumpfile=20080601schema.dmp schemas=hr

Export: Release 10.2.0.1.0 - Production on 星期三, 18 6月, 2008 16:04:16

Copyright (c) 2003, 2005, Oracle. All rights reserved.

连接到: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
启动 "HR"."SYS_EXPORT_SCHEMA_01": hr/******** directory=dump_dir dumpfile=20080601schema.dmp sche
s=hr
正在使用 BLOCKS 方法进行估计...
处理对象类型 SCHEMA_EXPORT/TABLE/TABLE_DATA
使用 BLOCKS 方法的总估计: 448 KB
处理对象类型 SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
处理对象类型 SCHEMA_EXPORT/SEQUENCE/SEQUENCE
处理对象类型 SCHEMA_EXPORT/TABLE/TABLE
处理对象类型 SCHEMA_EXPORT/TABLE/GRANT/OWNER_GRANT/OBJECT_GRANT
处理对象类型 SCHEMA_EXPORT/TABLE/INDEX/INDEX
处理对象类型 SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
处理对象类型 SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
处理对象类型 SCHEMA_EXPORT/TABLE/COMMENT
处理对象类型 SCHEMA_EXPORT/PROCEDURE/PROCEDURE
处理对象类型 SCHEMA_EXPORT/PROCEDURE/ALTER_PROCEDURE
处理对象类型 SCHEMA_EXPORT/VIEW/VIEW
处理对象类型 SCHEMA_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINT
处理对象类型 SCHEMA_EXPORT/TABLE/TRIGGER
处理对象类型 SCHEMA_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
. . 导出了 "HR"."COUNTRIES"                            6.085 KB      25 行
. . 导出了 "HR"."DEPARTMENTS"                          6.632 KB      27 行
. . 导出了 "HR"."EMPLOYEES"                            15.76 KB     107 行
. . 导出了 "HR"."JOBS"                                 6.609 KB      19 行
. . 导出了 "HR"."JOB_HISTORY"                          6.585 KB      10 行
. . 导出了 "HR"."LOCATIONS"                            7.710 KB      23 行
. . 导出了 "HR"."REGIONS"                              5.289 KB       4 行
已成功加载/卸载了主表 "HR"."SYS_EXPORT_SCHEMA_01"
******************************************************************************
HR.SYS_EXPORT_SCHEMA_01 的转储文件集为:
E:\DUMP\20080601SCHEMA.DMP
作业 "HR"."SYS_EXPORT_SCHEMA_01" 已于 16:04:50 成功完成


C:\>

如果没有授予hr用户操作dump_dir目录的权限,则会出现如下错误提示信息:
C:\>expdp hr/hr directory=dump_dir dumpfile=20080601schema.dmp schemas=hr

Export: Release 10.2.0.1.0 - Production on 星期三, 18 6月, 2008 16:02:55

Copyright (c) 2003, 2005, Oracle. All rights reserved.

连接到: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
ORA-39002: 操作无效
ORA-39070: 无法打开日志文件。
ORA-39087: 目录名 DUMP_DIR 无效

3、导出表空间
expdp system/sysadmin directory=dump_dir dumpfile=tablespace.dmp tablespaces=users

C:\>expdp system/sysadmin directory=dump_dir dumpfile=tablespace.dmp tablespaces=users

Export: Release 10.2.0.1.0 - Production on 星期三, 18 6月, 2008 16:09:19

Copyright (c) 2003, 2005, Oracle. All rights reserved.

连接到: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
启动 "SYSTEM"."SYS_EXPORT_TABLESPACE_01": system/******** directory=dump_dir dumpfile=tablespace.
p tablespaces=users
正在使用 BLOCKS 方法进行估计...
处理对象类型 TABLE_EXPORT/TABLE/TABLE_DATA
ORA-39139: 数据泵不支持 XMLSchema 对象。将跳过 TABLE_DATA:"OE"."PURCHASEORDER"。
使用 BLOCKS 方法的总估计: 1.187 MB
处理对象类型 TABLE_EXPORT/TABLE/TABLE
处理对象类型 TABLE_EXPORT/TABLE/INDEX/INDEX
处理对象类型 TABLE_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
处理对象类型 TABLE_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
处理对象类型 TABLE_EXPORT/TABLE/RLS_POLICY
处理对象类型 TABLE_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINT
处理对象类型 TABLE_EXPORT/TABLE/TRIGGER
. . 导出了 "OE"."LINEITEM_TABLE"                       283.5 KB    2232 行
. . 导出了 "OE"."ACTION_TABLE"                         14.87 KB     132 行
. . 导出了 "OE"."SUBCATEGORY_REF_LIST_NESTEDTAB"       6.398 KB      21 行
. . 导出了 "OE"."PRODUCT_REF_LIST_NESTEDTAB"           12.32 KB     288 行
. . 导出了 "OE"."CATEGORIES_TAB"                       13.12 KB      22 行
. . 导出了 "SCOTT"."DEPT"                              5.656 KB       4 行
. . 导出了 "SCOTT"."EMP"                               7.820 KB      14 行
. . 导出了 "SCOTT"."SALGRADE"                          5.585 KB       5 行
. . 导出了 "SCOTT"."BONUS"                                 0 KB       0 行
已成功加载/卸载了主表 "SYSTEM"."SYS_EXPORT_TABLESPACE_01"
******************************************************************************
SYSTEM.SYS_EXPORT_TABLESPACE_01 的转储文件集为:
E:\DUMP\TABLESPACE.DMP
作业 "SYSTEM"."SYS_EXPORT_TABLESPACE_01" 已经完成, 但是有 1 个错误 (于 16:09:48 完成)


C:\>


4、导出整个数据库

expdp system/sysadmin directory=dump_dir dumpfile=full.dmp full=y

*******************************************************************************************************************************************
对Oracle10g中的数据泵导入数据的分析
*******************************************************************************************************************************************

1、导入表

impdp scott/tiger directory=dump_dir dumpfile=dumptab.dmp tables=dept,emp

2、导入方案

一般只能导入自己的方案,如果想导入其他方案,必须具有EXP_FULL_DATABASE或者DBA权限。

impdp scott/tiger directory=dump_dir dumpfile=dumptab.dmp schemas=scott

3、导入表空间
impdp system/sysadmin directory=dump_dir dumpfile=tablespace.dmp tablespaces=users

4、导入整个数据库

impdp system/sysadmin directory=dump_dir dumpfile=full.dmp full=y


**************************************************************************************************************************************
使用Oracle10g的数据泵可以移动表空间
**************************************************************************************************************************************
使用impdp和expdp可以实现在不同的数据库之间移动表空间。在Oracle10g以前,只能在同一个操作系统平台
之间移动表空间。在Oracle10g之后,不仅可以在同一个操作系统平台之间移动表空间,还可以在不同的操作系统
之间移动表空间。用户可以通过查看数据库视图v$transportable_platform查询到哪些操作系统平台之间可以移动
表空间,即:

SQL> col platform_name format a60;
SQL> select * from v$transportable_platform order by platform_id;

PLATFORM_ID PLATFORM_NAME                                                ENDIAN_FORMAT
----------- ------------------------------------------------------------ --------------
          1 Solaris[tm] OE (32-bit)                                      Big
          2 Solaris[tm] OE (64-bit)                                      Big
          3 HP-UX (64-bit)                                               Big
          4 HP-UX IA (64-bit)                                            Big
          5 HP Tru64 UNIX                                                Little
          6 AIX-Based Systems (64-bit)                                   Big
          7 Microsoft Windows IA (32-bit)                                Little
          8 Microsoft Windows IA (64-bit)                                Little
          9 IBM zSeries Based Linux                                      Big
         10 Linux IA (32-bit)                                            Little
         11 Linux IA (64-bit)                                            Little

PLATFORM_ID PLATFORM_NAME                                                ENDIAN_FORMAT
----------- ------------------------------------------------------------ --------------
         12 Microsoft Windows 64-bit for AMD                             Little
         13 Linux 64-bit for AMD                                         Little
         15 HP Open VMS                                                  Little
         16 Apple Mac OS                                                 Big
         17 Solaris Operating System (x86)                               Little
         18 IBM Power Based Linux                                        Big

已选择17行。

要移动表空间必须满足如下条件:
1、原数据库和目标数据库必须有相同的数据库字符集和国家字符集
2、不能移动到具有同名表空间的目标数据库中。如果出现同名,只能使用ALTER TABLESPACE RENAME
命令更改源数据库或者目标数据库的表空间名称。
3、不能移动SYSTEM或者SYS用户对象所在的表空间。
4、要将表空间在不同的操作系统之间移动,必须将初始化参数COMPATIBLE参数设置为10.0以上。
因为Oracle10g以前的版本不支持在不同操作系统之间移动表空间。
5、要移动的表空间集合必须满足自包含,可以使用DBMS_TTS的过程TRANSPORT_SET_CHECK检查
是否自包含,然后在临时表transprot_set_violations内查询检查结果。

以下是移动表空间的步骤,以移动USERS表空间为例子:
第一步:设置表空间为只读表空间:
alter tablespace users read only;

第二步:使用expdp导出表空间
expdp 用户名/口令 directory=目录名称 dumpfile=导出文件名称 transport_tablespaces=表空间名称

例如:
expdp system/sysadmin directory=dump_dir dumpfile=tablespace.dmp tablespaces=users;

第三步:使用操作系统命令将导出文件和传输表空间的数据文件复制到目标数据库中。

第四步:在目标数据库上使用IMPDP将源数据库的导出内容导入到目标数据库中,IMPDP导入表空间的
命令格式如下:

IMP 用户名称/口令 directory=目录名称 dumpfile=导出文件名称 transport_tablespaces=表空间名称
transport_datafiles=;数据文件名称'

例如: 
impdp system/sysadmin directory=dump_dir dumpfile=tablespace.dmp tablespaces=users
transport_datafiles=D:\oracle\oradata\oramgr\user01.dbf;

第五步:使用一下命令将原数据库的传输表空间恢复为可读写
alter tablespace users read write;


Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
oracle怎么查询所有索引oracle怎么查询所有索引May 13, 2022 pm 05:23 PM

方法:1、利用“select*from user_indexes where table_name=表名”语句查询表中索引;2、利用“select*from all_indexes where table_name=表名”语句查询所有索引。

什么是oracle asm什么是oracle asmApr 18, 2022 pm 04:16 PM

oracle asm指的是“自动存储管理”,是一种卷管理器,可自动管理磁盘组并提供有效的数据冗余功能;它是做为单独的Oracle实例实施和部署。asm的优势:1、配置简单、可最大化推动数据库合并的存储资源利用;2、支持BIGFILE文件等。

oracle全角怎么转半角oracle全角怎么转半角May 13, 2022 pm 03:21 PM

在oracle中,可以利用“TO_SINGLE_BYTE(String)”将全角转换为半角;“TO_SINGLE_BYTE”函数可以将参数中所有多字节字符都替换为等价的单字节字符,只有当数据库字符集同时包含多字节和单字节字符的时候有效。

Oracle怎么查询端口号Oracle怎么查询端口号May 13, 2022 am 10:10 AM

在Oracle中,可利用lsnrctl命令查询端口号,该命令是Oracle的监听命令;在启动、关闭或重启oracle监听器之前可使用该命令检查oracle监听器的状态,语法为“lsnrctl status”,结果PORT后的内容就是端口号。

oracle怎么删除sequenceoracle怎么删除sequenceMay 13, 2022 pm 03:35 PM

在oracle中,可以利用“drop sequence sequence名”来删除sequence;sequence是自动增加数字序列的意思,也就是序列号,序列号自动增加不能重置,因此需要利用drop sequence语句来删除序列。

oracle怎么查询数据类型oracle怎么查询数据类型May 13, 2022 pm 04:19 PM

在oracle中,可以利用“select ... From all_tab_columns where table_name=upper('表名') AND owner=upper('数据库登录用户名');”语句查询数据库表的数据类型。

oracle查询怎么不区分大小写oracle查询怎么不区分大小写May 10, 2022 pm 05:45 PM

方法:1、利用“LOWER(字段值)”将字段转为小写,或者利用“UPPER(字段值)”将字段转为大写;2、利用“REGEXP_LIKE(字符串,正则表达式,'i')”,当参数设置为“i”时,说明进行匹配不区分大小写。

Oracle怎么修改sessionOracle怎么修改sessionMay 13, 2022 pm 05:06 PM

方法:1、利用“alter system set sessions=修改后的数值 scope=spfile”语句修改session参数;2、修改参数之后利用“shutdown immediate – startup”语句重启服务器即可生效。

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool