java oracle sqlldr,oracle sqlldr

sql loader可以把一些以文本格式存放的数据顺利地导入到中,它是一种在不同数据库之间进行数据迁移非常方便而且通用的工具。缺点就是速度比较慢,另外对blob等类型的数据就有点麻烦了。

一、用法:SQLLDR keyword=value [,keyword=value,...]

二、有效的关键字:

userid -- ORACLE username/password

control –控制文件

log –记录的日志文件

bad –坏数据文件

data –数据文件

discard –丢弃的数据文件

discardmax–允许丢弃数据的最大值(全部默认)

skip -- Number of logical records to skip  (默认0)

load -- Number of logical records to load  (全部默认)

errors –允许的错误记录数(默认50)

rows -- Number of rows in conventional path bind array or between direct path data saves(每次提交的记录数,默认:常规路径64,所有直接路径)

bindsize -- Size of conventional path bind array in bytes(默认256000)

每次提交记录的缓冲区的大小(字节为单位,默认256000)

silent --禁止输出信息(header,feedback,errors,discards,partitions)

direct –使用直通路径方式导入(默认FALSE)

parfile -- parameter file: name of file that contains parameter specifications

parallel --并行导入(默认FALSE)

file -- File to allocate extents from

skip_unusable_indexes-- disallow/allow unusable indexes or index partitions(默认FALSE)

skip_index_maintenance-- do not maintain indexes, mark affected indexes as unusable(默认FALSE)

readsize -- Size of Read buffer                (默认1048576)

与bindsize成对使用,其中较小者会自动调整到较大者。sqlldr先计算单条记录长度,乘以rows,如小于bindsize,不会试图扩张rows以填充bindsize;如超出,则以bindsize为准。

external_table-- use external table for load; NOT_USED, GENERATE_ONLY, EXECUTE(默认NOT_USED)

columnarrayrows-- Number of rows for direct path column array(默认5000)

streamsize-- Size of direct path stream buffer in bytes(默认256000)

multithreading-- use multithreading in direct path

resumable -- enable or disable resumable for current session(默认FALSE)

resumable_name-- text string to help identify resumable statement

resumable_timeout-- wait time (in seconds) for RESUMABLE(默认7200)

date_cache-- size (in entries) of date conversion cache(默认1000)

注意:有两种方式可以指定命令行参数:通过位置或者通过关键字。

(1)通过位置指定命令行参数的例子:'sqlldr scott/tiger foo';

(2)通过关键字指定命令行参数的例子:'sqlldr control=foo userid=scott/tiger';

不能前面使用关键字指定后面通过位置指定的混合方式;

比如:'sqlldr scott/tiger control=foo logfile=log'是允许的;

但'sqlldr scott/tiger control=foo log'不允许。

通过位置指定命令行参数的时候,必须将“位置”放在user/passwd之前。

为清楚起见最好所有命令行参数都用关键字指定。

三、控制文件:一个控制命令的脚本文件,通常以ctl结尾,内容如下:

LOAD DATA

INFILE't.dat'             //要导入的文件

// INFILE 'tt.date'        //导入多个文件

// INFILE *              //表示要导入的内容就在control文件里下面的BEGINDATA后面就是导入的内容

INTO TABLEtable_name  //指定装入的表

BADFILE'c:\bad.txt'    //可选,指定坏文件地址,缺省在当前目录下生成与原文件名一致的.bad文件

//*************以下是4种装入表的方式

APPEND//原先的表有数据就加在后面

// INSERT            //装载空表如果原先的表有数据sqlloader会停止默认值

// REPLACE       //原先的表有数据原先的数据会全部删除

// TRUNCATE            //指定的内容和replace的相同会用truncate语句删除现存数据

//*************指定分隔符

FIELDS TERMINATED BY',' OPTIONALLY ENCLOSED BY '"'

// TERMINATED BY WRITESPACE //以空白分割

TRAILING NULLCOLS//表的字段没有对应的值时允许为空

*************下面是表的字段

(

col_1 , col_2 ,col_filler FILLER// FILLER关键字此列的数值不会被装载

//如: lg,lg,not结果lg lg

)

如果没声明FIELDS TERMINATED BY ','时,可以用下面两种方式实现同样功能:

(1)、为每一列指定分隔符

(

col_1 [interger external] TERMINATED BY ',' ,

col_2 [date "dd-mon-yyy"] TERMINATED BY ',' ,

col_3 [char] TERMINATED BY ',' OPTIONALLY ENCLOSED BY 'lg'

)

(2)、用位置告诉字段装载数据

(

col_1 position(1:2),

col_2 position(3:10),

col_3 position(*:16), //这个字段的开始位置在前一字段的结束位置

col_4 position(1:16),

col_5 position(3:10) char(8) //指定字段的类型

)

BEGINDATA         //对应开始的INFILE *要导入的内容就在control文件里

10,,what

20,lg,show

例子:

[oracle@ZR230-117 ~]$ vi a.ctl

Esc i

options (bindsize=655360,direct=true)

load data

infile '/usr/oracle/checkcode5.csv'

Append into table img_authcode

fields terminated by ';'

(pic_id,authcode,path)

:wq!

注:# bindsize每次提交记录的缓冲区direct使用直通方式,缺省为false

#读取'/usr/oracle/checkcode5.csv'这个excl文件

#添加到img_authcode这个表里

#每个字段间以“;”隔开

#分别对应pic_id,authcode,path这三个字段

#如果只导入一列,那么要注意用position标识一下字段长度:

options (bindsize=655360,direct=true)

load data

infile 'sex.txt'

insert into table id_temp

(id position(1:10))//从第一个字节开始到第十个结束

导入控制文件

[oracle@ZR230-117 ~]$ sqlldr member/member control=a.ctl

提示完成:

SQL*Loader: Release10.2.0.2.0 - Production on Thu Mar 20 09:47:24

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

Load completed - logical record count 10000.

查看一下,有无错误:

[oracle@ZR230-117 ~]$ more a.log

SQL*Loader: Release10.2.0.2.0 - Production on Thu Mar 20 09:47:24 2008

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

Control File:a.ctl

Data File:/usr/oracle/checkcode5.csv

Bad File:checkcode5.bad

Discard File:none specified

(Allow all discards)

Number to load: ALL

Number to skip: 0

Errors allowed: 50

Continuation:none specified

Path used:Direct

Table IMG_AUTHCODE, loaded from every logical record.

Insert option in effect for this table: APPEND

Column NamePositionLenTerm Encl Datatype

------------------------------ ---------- ----- ---- ---- ---------------------

PIC_IDFIRST*;CHARACTER

AUTHCODENEXT*;CHARACTER

PATHNEXT*;CHARACTER

The following index(es) on table IMG_AUTHCODE were processed:

index MEMBER.SYS_C0020883 loaded successfully with 10000 keys

Table IMG_AUTHCODE:

10000 Rows successfully loaded.

0 Rows not loaded due to data errors.

0 Rows not loaded because all WHEN clauses were failed.

0 Rows not loaded because all fields were null.

Bind array size not used in direct path.

Column arrayrows :5000

Stream buffer bytes:256000

Readbuffer bytes: 1048576

Total logical records skipped:0

Total logical records read:10000

Total logical records rejected:0

Total logical records discarded:0

Total stream buffers loaded by SQL*Loader main thread:2

Total stream buffers loaded by SQL*Loader load thread:0

Run began on Thu Mar 20 09:47:24 2008

Run ended on Thu Mar 20 09:47:25 2008

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值