Sql*loader

Oracle 11.2



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


有效的关键字:


  userid -- ORACLE 用户名/口令

 control -- 控制文件名

     log -- 日志文件名

     bad -- 错误文件名

    data -- 数据文件名

 discard -- 废弃文件名

discardmax -- 允许废弃的文件的数目         (全部默认)

    skip -- 要跳过的逻辑记录的数目  (默认 0)

    load -- 要加载的逻辑记录的数目  (全部默认)

  errors -- 允许的错误的数目         (默认 50)

    rows -- 常规路径绑定数组中或直接路径保存数据间的行数

              (默认: 常规路径 64, 所有直接路径)

bindsize -- 常规路径绑定数组的大小 (以字节计)  (默认 256000)

  silent -- 运行过程中隐藏消息 (标题,反馈,错误,废弃,分区)

  direct -- 使用直接路径                     (默认 FALSE)

 parfile -- 参数文件: 包含参数说明的文件的名称

parallel -- 执行并行加载                    (默认 FALSE)

    file -- 要从以下对象中分配区的文件

skip_unusable_indexes -- 不允许/允许使用无用的索引或索引分区  (默认 FALSE)

skip_index_maintenance -- 没有维护索引, 将受到影响的索引标记为无用  (默认 FALSE)


commit_discontinued -- 提交加载中断时已加载的行  (默认 FALSE)

readsize -- 读取缓冲区的大小               (默认 1048576)

external_table -- 使用外部表进行加载;NOT_USED, GENERATE_ONLY, EXECUTE  (默认 NO

T_USED)

columnarrayrows -- 直接路径列数组的行数  (默认 5000)

streamsize -- 直接路径流缓冲区的大小 (以字节计)  (默认 256000)

multithreading -- 在直接路径中使用多线程

resumable -- 启用或禁用当前的可恢复会话  (默认 FALSE)

resumable_name -- 有助于标识可恢复语句的文本字符串

resumable_timeout -- RESUMABLE 的等待时间 (以秒计)  (默认 7200)

date_cache -- 日期转换高速缓存的大小 (以条目计)  (默认 1000)

no_index_errors -- 出现任何索引错误时中止加载  (默认 FALSE)


PLEASE NOTE: 命令行参数可以由位置或关键字指定

。前者的例子是 'sqlldr

scott/tiger foo'; 后一种情况的一个示例是'sqlldr control=foo

userid=scott/tiger'。位置指定参数的时间必须早于

但不可迟于由关键字指定的参数。例如,

允许 'sqlldr scott/tiger control=foo logfile=log', 但是

不允许 'sqlldr scott/tiger control=foo log', 即使

参数 'log' 的位置正确。


参数的OPTIONS Clause

specify command-line parameters in theSQL*Loader control file using the OPTIONS clause. This can be useful when youtypically invoke a control file with the same set of options. The OPTIONSclause precedes the LOAD DATA statement.

BINDSIZE = n
COLUMNARRAYROWS = n
DATE_CACHE = n
DIRECT = {TRUE | FALSE} 
ERRORS = n
EXTERNAL_TABLE = {NOT_USED | GENERATE_ONLY | EXECUTE}
FILE
LOAD = n
MULTITHREADING = {TRUE | FALSE}
PARALLEL = {TRUE | FALSE}
READSIZE = n
RESUMABLE = {TRUE | FALSE}
RESUMABLE_NAME = 'text string'
RESUMABLE_TIMEOUT = n
ROWS = n 
SILENT = {HEADER | FEEDBACK | ERRORS | DISCARDS | PARTITIONS | ALL} 
SKIP = n   
SKIP_INDEX_MAINTENANCE = {TRUE | FALSE}
SKIP_UNUSABLE_INDEXES = {TRUE | FALSE}
STREAMSIZE = n




实例:

sqlldr userid=user/passwordcontrol=vav_dvd_config.ctl log=test.log


如果连接远程服务器如下:

sqlldr control=vav_dvd_config.ctllog=test.log

Username:name@dbinstance

Password:password

在这里的dbinstance oracle客户端中的tnsname.ora文件描述的连接字符串名称。


Sql*loader of Overview.


A typical SQL*Loader session takes as inputa control file, which controls the behavior of SQL*Loader, and one or more datafiles. The output of SQL*Loader is an Oracle database (where the data isloaded), a log file, a bad file, and potentially, a discard file. An example ofthe flow of a SQL*Loader session is shown


134929793.gif


上图是sqlldr常用的几个文件。下来解释下这几个文件:

1、controlfile


The SQL*Loader control file is a text filethat contains data definition language (DDL) instructions. DDL is used tocontrol the following aspects of a SQL*Loader session:


Where SQL*Loader will find the data to load

How SQL*Loader expects that data to beformatted

How SQL*Loader will be configured (memorymanagement, rejecting records, interrupted load handling, and so on) as itloads the data

How SQL*Loader will manipulate the databeing loaded


例如:

1   -- This is a sample control file

2   LOAD DATA

3    INFILE'sample.dat'

4   BADFILE 'sample.bad'

5   DISCARDFILE 'sample.dsc'

6   APPEND

7   INTO TABLE emp

8   WHEN (57) = '.'

9   TRAILING NULLCOLS

10 (hiredate SYSDATE,

     deptno POSITION(1:2)  INTEGER EXTERNAL(2)

             NULLIF deptno=BLANKS,

      job    POSITION(7:14)  CHAR TERMINATED BY WHITESPACE

             NULLIF job=BLANKS  "UPPER(:job)",

      mgr    POSITION(28:31) INTEGER EXTERNAL

             TERMINATED BYWHITESPACE, NULLIF mgr=BLANKS,

      ename  POSITION(34:41) CHAR

             TERMINATED BY WHITESPACE  "UPPER(:ename)",

      empno  POSITION(45) INTEGER EXTERNAL

             TERMINATED BYWHITESPACE,

      sal    POSITION(51) CHAR  TERMINATED BY WHITESPACE

            "TO_NUMBER(:sal,'$99,999.99')",

      comm   INTEGER EXTERNAL  ENCLOSED BY '(' AND '%'

             ":comm *100"

   )


这是一个简单的例子,数字110在实际脚本中是不写的。下面对这个例子进行说明:

1、

2、Load date 告诉 sql*loader 开始数据装载

3、Inflie是要load的文件名称,里面是数据表的内容。文件可以是txt,csv等常用格式。

4、Badfile是装载过程中被拒绝的数据被存放在badfile中。

5、Discardfile 是装载过程中丢弃的记录存在discardfile

6、Append是对非空表中数据保持不变,然后继续插入数据。例子中Emp表是非空表,那么sqlloader导入时,会在原有的数据的基础上导入数据。

7、Into table 是指定导入对象,字段以及字段类型。关联操作系统文件中的记录和数据库表之间。

8、When 语句是指定限制条件如’,’ or ‘.’ ,在CSV中会以,号来区别开来。那么数据会做遇到“,”就会插入到对表中的列字段中去。

9、Trailing nullcols 是在相对应表中的列,如果没有数据记录则表示代表为null columns

10、包含是关于表中的列字段的部分,这里经常会用到列段的格式问题。


当然sql*loader中还有很多参数,在这里就不提了。这里只讲讲常用的参数。例如:


lFILE (tablespace file to load into)

Default: none


FILE specifies the database file toallocate extents from. It is used only for direct path parallel loads. Byvarying the value of the FILE parameter for different SQL*Loader processes,data can be loaded onto a system with minimal disk contention.


lLOG (log file)

Default: The name of the control file, withan extension of .log.


LOG specifies the log file that SQL*Loaderwill create to store logging information about the loading process.


lMULTITHREADING

Default: true on multiple-CPU systems,false on single-CPU systems


This parameter is available only for directpath loads.


By default, the multithreading option isalways enabled (set to true) on multiple-CPU systems. In this case, thedefinition of a multiple-CPU system is a single system that has more than oneCPU.


On single-CPU systems, multithreading isset to false by default. To use multithreading between two single-CPU systems,you must enable multithreading; it will not be on by default. This will allowstream building on the client system to be done in parallel with stream loadingon the server system.


Multithreading functionality is operatingsystem-dependent. Not all operating systems support multithreading.


lPARALLEL (parallel load)


Default: false


PARALLEL specifies whether direct loads canoperate in multiple concurrent sessions to load data into the same table.

等等。在面对导入大数据量的时候,需要重新考虑下参数的应用。比如:并行,表索引等等。所以说在面对不同的数据量时,大家选择的参数文件可能不一样。


参考文档:

http://docs.oracle.com/cd/E11882_01/server.112/e22490/ldr_control_file.htm#i1005907

SQL*Loader control file reference

http://docs.oracle.com/cd/E11882_01/server.112/e22490/ldr_params.htm#i1004682

SQL*Loader Command-Line Reference

http://docs.oracle.com/cd/E11882_01/server.112/e22490/ldr_concepts.htm#i1006494

SQL*Loader Concepts