oracle 外部表之 sqlldr 生成

oracle的导入工具,速度挺快,这里记一下外部表的使用,通常外部表要记的语法太多例如:

CREATE TABLE PROD_MASTER 
(
  "EMPNO" NUMBER,"ENAME" VARCHAR2(50),"HIREDATE" DATE,"DEPTNO" NUMBER
)
ORGANIZATION external 
(
  TYPE oracle_loader
  DEFAULT DIRECTORY ext_table
  ACCESS PARAMETERS 
  (
    RECORDS DELIMITED BY NEWLINE CHARACTERSET US7ASCII
    preprocessor ext_table:'uncompress.sh'    
    BADFILE 'EXT_TABLE':'prod_master.dat.bad'
    LOGFILE '1.log_xt'
    READSIZE 1048576
    FIELDS TERMINATED BY "," LDRTRIM 
    MISSING FIELD VALUES ARE NULL 
    REJECT ROWS WITH ALL NULL FIELDS 
    (
      "EMPNO" CHAR(255)
        TERMINATED BY ",","ENAME" CHAR(255)
        TERMINATED BY ","HIREDATE" CHAR(10)
        TERMINATED BY ","
        DATE_FORMAT DATE MASK 'dd-mon-yyyy',"DEPTNO" CHAR(255)
        TERMINATED BY ","
    )
  )
  location 
  (
    'prod_master.dat.gz'
  )
)REJECT LIMIT UNLIMITED

如果全靠手打,这个工作量有点大,可以考虑系统自己生成,步骤如下:
1 检查组件:

SELECT * FROM V$OPTION WHERE PARAMETER = 'Oracle Database Vault';
select comp_id,comp_name,version,status from dba_registry;
chopt disable dv

如果不关

sql> select * from prod_master;
select * from prod_master
*
ERROR at line 1:
ORA-29913: error in executing ODCIEXTTABLEOPEN callout
ORA-29400: data cartridge error
KUP-04094: preprocessing cannot be performed if Database Vault is installed

2 创建表

CREATE TABLE PROD_MASTER 
(
  "EMPNO" NUMBER,"DEPTNO" NUMBER
)

3 创建控制文件
cat prod_master.ctl

load data
infile '/home/oracle/scripts/prod_master.dat.gz'
append 
into table prod_master
fields terminated by ","
trailing nullcols
(empno,ename,hiredate date(10) 'dd-mon-yyyy',deptno)

4创建存放目录

create directory ext as '/home/oracle/ext';
grant read,write,execute on ext;

5 生成建外部表的语句
sqlldr userid=hr/hr control=prod_master.ctl extern_table=gernerate_only log=create_table.sql
由于启用了压缩,修改其中:
PREPROCESSOR EXT:'uncompress.sh' --Preprocessor before readsize

相关文章

数据库版本:11.2.0.4 RAC(1)问题现象从EM里面可以看到,在23号早上8:45~8:55时,数据库等待会话暴增...
(一)问题背景最近在对一个大约200万行数据的表查看执行计划时,发现存在异常,理论上应该返回100多万...
(一)删除备份--DELETE命令用于删除RMAN备份记录及相应的物理文件。当使用RMAN执行备份操作时,会在RM...
(1)DRA介绍 数据恢复顾问(Data Recovery Advise)是一个诊断和修复数据库的工具,DRA能够修复数据文...
RMAN(Recovery Manager)是Oracle恢复管理器的简称,是集数据库备份(backup)、修复(restore)和恢复...
(1)备份对象 可以使用RMAN进行的备份对象如下: --整个数据库:备份所有的数据文件和控制文件; --数...