OCM实验-外部表

要求从PROD数据库卸载数据,然后再OCM2库加载该数据,使用数据泵的方式。

外部表适用于导出的数据可用于二次开发或者数据迁移

 

1)从PROD数据库导出数据

SYS@PROD>create user exp identified by exp default tablespace users;

User created.

SYS@PROD>grant dba to exp;

Grant succeeded.

SYS@PROD>create directory dir_tmp as '/home/oracle';

Directory created.

SYS@PROD>grant read,write on directory dir_tmp to exp;

Grant succeeded.

创建外部表,使用数据泵卸载数据

SYS@PROD>conn exp/exp
Connected.
EXP@PROD>
EXP@PROD>create table t organization external                                                
  2  (type oracle_datapump
  3  default directory dir_tmp
  4  location ('t_part1_dump.dat','t_part2_dump.dat')
  5  )
  6  parallel 2  
  7  as
  8  select owner,object_id,object_name from dba_objects where owner='SYSTEM';

Table created.

EXP@PROD>

2)将生成的文件传递到OCM2主机

-rw-r----- 1 oracle oinstall     20480 Jan 20 14:32 t_part1_dump.dat
-rw-r----- 1 oracle oinstall     20480 Jan 20 14:32 t_part2_dump.dat

[oracle@ocm1 ~]$ scp t_part* oracle@ocm2:~
t_part1_dump.dat                                                                                                          100%   20KB  20.0KB/s   00:00   
t_part2_dump.dat                                                                                                          100%   20KB  20.0KB/s   00:00

3)在OCM2库,建imp账户并创建外部表t1表来加载数据

SYS@OCM2>grant dba to imp;  

Grant succeeded.

SYS@OCM2>create directory dir_tmp as '/home/orace';

Directory created.

grant">SYS@OCM2>grant read,write on directory dir_tmp to imp;

Grant succeeded.

SYS@OCM2>conn imp/imp
Connected.

创建外部表并加载数据

IMP@OCM2>create table t1 (owner varchar2(30),object_id number,object_name varchar2(128)) organization external
  2  (type oracle_datapump
  3  default directory dir_tmp
  4  location ('t_part1_dump.dat','t_part2_dump.dat'));

Table created.

测试

IMP@OCM2>select count(*) from t1;
select count(*) from t1
*
ERROR at line 1:
ORA-29913: error in executing ODCIEXTTABLEOPEN callout
ORA-29400: data cartridge error
KUP-04063: unable to open log file T1_31553.log
OS error No such file or directory
ORA-06512: at "SYS.ORACLE_DATAPUMP", line 19

检查是否可以使用expdp 导出

[oracle@ocm2 ~]$ expdp imp/imp  directory=dir_tmp dumpfile=objects.dat

Export: Release 10.2.0.1.0 - Production on Monday, 20 January, 2014 14:49:06

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

Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
ORA-39002: invalid operation
ORA-39070: Unable to open the log file.
ORA-29283: invalid file operation
ORA-06512: at "SYS.UTL_FILE", line 475
ORA-29283: invalid file operation

检查了半天,原来是路径写错误了。哎。

SYS@OCM2>drop directory dir_tmp;

Directory dropped.

SYS@OCM2>create directory dir_tmp as '/home/oracle';

Directory created.

SYS@OCM2>grant read,write on directory dir_tmp to imp;

Grant succeeded.

SYS@OCM2>conn imp/imp
Connected.
IMP@OCM2>
IMP@OCM2>
IMP@OCM2>select count(*) from t1;

  COUNT(*)
----------
       449

IMP@OCM2>

深入学习一下

type参数:

Oracle Database provides two access drivers for external tables. The default access driver is ORACLE_LOADER, which allows the reading of data from external files using the Oracle loader technology. The ORACLE_LOADER access driver provides data mapping capabilities which are a subset of the control file syntax of SQL*Loader utility. The second access driver, ORACLE_DATAPUMP, lets you unload data--that is, read data from the database and insert it into an external table, represented by one or more external files--and then reload it into an Oracle Database.

使用sql loader 方式创建外部表并加载数据

1)新建两个外部文件

[oracle@ocm1 ~]$ cat empxt1.dat
360,Jane,Janus,ST_CLERK,121,17-MAY-2001,3000,0,50,jjanus
361,Mark,Jasper,SA_REP,145,17-MAY-2001,8000,.1,80,mjasper
362,Brenda,Starr,AD_ASST,200,17-MAY-2001,5500,0,10,bstarr
363,Alex,Alda,AC_MGR,145,17-MAY-2001,9000,.15,80,aalda
[oracle@ocm1 ~]$ cat empxt2.dat
401,Jesse,Cromwell,HR_REP,203,17-MAY-2001,7000,0,40,jcromwel
402,Abby,Applegate,IT_PROG,103,17-MAY-2001,9000,.2,60,aapplega
403,Carol,Cousins,AD_VP,100,17-MAY-2001,27000,.3,90,ccousins
404,John,Richardson,AC_ACCOUNT,205,17-MAY-2001,5000,0,110,jrichard

2)创建外部表

这个过程使用上面测试中的directory dir_tmp 。

EXP@PROD>create table employees
  2  (employee_id       NUMBER(4),
  3  first_name        VARCHAR2(20),
  4  last_name         VARCHAR2(25),
  5  job_id            VARCHAR2(10),
  6  manager_id        NUMBER(4),
  7  hire_date         DATE,
  8  salary            NUMBER(8,2),
  9  commission_pct    NUMBER(2,2),
10  department_id     NUMBER(4),
11  email             VARCHAR2(25))
12  organization external
13  (type oracle_loader
14  default directory dir_tmp
15  ACCESS PARAMETERS
16         (
17           records delimited by newline
18           badfile dir_tmp:'empxt%a_%p.bad'
19           logfile dir_tmp:'empxt%a_%p.log'
20           fields terminated by ','
21           missing field values are null
22           ( employee_id, first_name, last_name, job_id, manager_id,
23             hire_date char date_format date mask "dd-mon-yyyy",
24             salary, commission_pct, department_id, email
25           )
26  )
27  LOCATION ('empxt1.dat', 'empxt2.dat')
28  )
29  PARALLEL
30  REJECT LIMIT UNLIMITED;

Table created.

测试:

EXP@PROD>select count(*) from employees;

  COUNT(*)
----------
         8

EXP@PROD>

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/11590946/viewspace-1073126/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/11590946/viewspace-1073126/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
资源包主要包含以下内容: ASP项目源码:每个资源包中都包含完整的ASP项目源码,这些源码采用了经典的ASP技术开发,结构清晰、注释详细,帮助用户轻松理解整个项目的逻辑和实现方式。通过这些源码,用户可以学习到ASP的基本语法、服务器端脚本编写方法、数据库操作、用户权限管理等关键技术。 数据库设计文件:为了方便用户更好地理解系统的后台逻辑,每个项目中都附带了完整的数据库设计文件。这些文件通常包括数据库结构图、数据设计文档,以及示例数据SQL脚本。用户可以通过这些文件快速搭建项目所需的数据库环境,并了解各个数据之间的关系和作用。 详细的开发文档:每个资源包都附有详细的开发文档,文档内容包括项目背景介绍、功能模块说明、系统流程图、用户界面设计以及关键代码解析等。这些文档为用户提供了深入的学习材料,使得即便是从零开始的开发者也能逐步掌握项目开发的全过程。 项目演示与使用指南:为帮助用户更好地理解和使用这些ASP项目,每个资源包中都包含项目的演示文件和使用指南。演示文件通常以视频或图文形式展示项目的主要功能和操作流程,使用指南则详细说明了如何配置开发环境、部署项目以及常见问题的解决方法。 毕业设计参考:对于正在准备毕业设计的学生来说,这些资源包是绝佳的参考材料。每个项目不仅功能完善、结构清晰,还符合常见的毕业设计要求和标准。通过这些项目,学生可以学习到如何从零开始构建一个完整的Web系统,并积累丰富的项目经验。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值