最近由于遇到oracle控制文件的使用,虽然不是很复杂,但是从来没有用过,专门花点时间看看。点击 这里 查看详细

1,概述:

Sql Loader: 一个批量工具,将文件数据导入到数据库。可以导入一个表或者多个表,甚至可以在导入时修改数据。

2,使用

a,你电脑需要装Oracle,不然你是找不到Sqlldr 这个命令的。

在控制输入台输入 sqlldr:

会列出相关的参数介绍。

> sqlldr
.
.
.
Usage: SQLLDR keyword=value [,keyword=value,...] Valid Keywords: userid -- ORACLE username/password
control -- control file name
log -- log file name
bad -- bad file name
data -- data file name
discard -- discard file name
discardmax -- number of discards to allow (Default all)
skip -- number of logical records to skip (Default 0)
load -- number of logical records to load (Default all)
errors -- number of errors to allow (Default 50)
rows -- number of rows in conventional path bind array or between direct
path data saves
(Default: Conventional path 64, Direct path all)
bindsize -- size of conventional path bind array in bytes (Default 256000)
silent -- suppress messages during run (header,feedback,errors,discards,
partitions)
direct -- use direct path (Default FALSE)
parfile -- parameter file: name of file that contains parameter specifications
parallel -- do parallel load (Default FALSE)
file -- file to allocate extents from
skip_unusable_indexes -- disallow/allow unusable indexes or index partitions
(Default FALSE)
skip_index_maintenance -- do not maintain indexes, mark affected indexes as
unusable (Default FALSE)
commit_discontinued -- commit loaded rows when load is discontinued (Default
FALSE)
readsize -- size of read buffer (Default 1048576)
external_table -- use external table for load; NOT_USED, GENERATE_ONLY, EXECUTE
(Default NOT_USED)
columnarrayrows -- number of rows for direct path column array (Default 5000)
streamsize -- size of direct path stream buffer in bytes (Default 256000)
multithreading -- use multithreading in direct path
resumable -- enable or disable resumable for current session (Default FALSE)
resumable_name -- text string to help identify resumable statement
resumable_timeout -- wait time (in seconds) for RESUMABLE (Default 7200)
date_cache -- size (in entries) of date conversion cache (Default 1000) PLEASE NOTE: Command-line parameters may be specified either by position or by keywords.
An example of the former case is 'sqlldr scott/tiger foo'; an example of the latter
is 'sqlldr control=foo userid=scott/tiger'.One may specify parameters by position before
but not after parameters specified by keywords.For example, 'sqlldr scott/tiger control=foo
logfile=log' is allowed, but 'sqlldr scott/tiger control=foo log' is not, even though the
position of the parameter 'log' is correct.

b, sqlldr 将文本文件的导入到数据库

这里看个简单例子。看看sqlldr到底怎么工作的。

1,准备数据文件,例如input.txt.这个文件将导入到数据库中。

首先查看我们数据库的表格式。

create table student(
SNAME VARCHAR(20),
SAGE INTEGER,
SEMAIL VARCHAR(20),
SPHONE VARCHAR(20),
SADDRESS VARCHAR(20)
)

input.txt 文件

12,12,abc@gmail.com,12,address
13,13,abc@gmail.com,13,address
14,14,abc@gmail.com,14,address
15,15,abc@gmail.com,15,address
16,16,abc@gmail.com,16,address
17,17,abc@gmail.com,17,address
18,18,abc@gmail.com,18,address
19,19,abc@gmail.com,19,address

2,控制文件input.ctl

load data
infile 'input.txt'
append into table student --这里用的Append.
fields terminated by "," --这里表示逗号分割。
(SNAME,SAGE,SEMAIL,SPHONE,SADDRESS)

这里用的Append, 追加数据,还有几个其他的参数:

a,insert,为缺省方式,在数据装载开始时要求表为空

b,append,在表中追加新记录

c ,replace,删除旧记录,替换成新装载的记录

d,truncate,同上

3,sqlldr 调用控制文件

sqlldr username/password@Database control =input.ctl             //input.ctl 为控制文件

在这里需要提下,这里是会生成日志文件,默认为文件名文件名+.log. 当前为 input.log

如果执行失败了,会生成bad file. 如果在当前执行中错误,会生成input.bad file。

下面指定Log 和bad 文件,当然可以加上路径

sqlldr userid=username/password@database control=input.ctl log=input.log bad=input.bad  SILENT=(HEADER, FEEDBACK)

SILENT=(HEADER, FEEDBACK) 控制端不显示信息,例如下面的信息将不再控制端显示。只在日志文件中

Record 4: Rejected - Error on table EMP
ORA-00001: unique constraint <name> violated

当然是可以显示指定的。

load data
infile input.txt
badfile t.bad
discardfile t.dsc
append into table student
fields terminated by ","
(SNAME,SAGE,SEMAIL,SPHONE,SADDRESS)

看看日志文件:input.log

SQL*Loader: Release 10.2.0.1.0 - Production on Tue May 20 17:36:52 2014

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

Control File:   input1.ctl
Data File: input1.ctl
Bad File: input1.bad
Discard File: none specified (Allow all discards) Number to load: ALL
Number to skip: 0
Errors allowed: 50
Bind array: 64 rows, maximum of 256000 bytes
Continuation: none specified
Path used: Conventional Table STUDENT, loaded from every logical record.
Insert option in effect for this table: APPEND Column Name Position Len Term Encl Datatype
------------------------------ ---------- ----- ---- ---- ---------------------
SNAME FIRST * , CHARACTER
SAGE NEXT * , CHARACTER
SEMAIL NEXT * , CHARACTER
SPHONE NEXT * , CHARACTER
SADDRESS NEXT * , CHARACTER Table STUDENT:
1 Row 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. Space allocated for bind array: 82560 bytes(64 rows)
Read buffer bytes: 1048576 Total logical records skipped: 0
Total logical records read: 1
Total logical records rejected: 0
Total logical records discarded: 0 Run began on Tue May 20 17:36:52 2014
Run ended on Tue May 20 17:36:52 2014 Elapsed time was: 00:00:00.05
CPU time was: 00:00:00.04

4,查看数据库

到此一个简单的例子完成,从一个文本文件导入到数据库。

文件可以为不同格式文件,.dat,.csv都可以的。

C,sqlldr直接在控制文件中导入数据。

load data
infile *
append into table student
fields terminated by ","
(SNAME,SAGE,SEMAIL,SPHONE,SADDRESS)
begindata
20,20,abc@gmail.com,20,address --这里是数据

D,当文件数据是以绝对位置分开的,我们可以直接截取。当然,截取的开始与结束必须小心了。

load data
infile t.dat
append into table student
(SNAME position(01:20),
SAGE position(21:23) ,
SEMAIL position(41:60),
SPHONE position(61:80),
SADDRESS position(81:100)
)

t.dat 文件

Jack                12                  abc@gmail.com       134998879           Singapore
Jack2 12 abc@gmail.com 134998879 Singapore
Jack3 12 abc@gmail.com 134998879 Singapore
Jack4 12 abc@gmail.com 134998879 Singapore
Jack5 12 abc@gmail.com 134998879 Singapore
Jack6 12 abc@gmail.com 134998879 Singapore
Jack7 12 abc@gmail.com 134998879 Singapore

还数据在Load to database 的时候,load的数据是可以改变的。

LOAD DATA
INFILE *
INTO TABLE modified_data
( rec_no "my_db_sequence.nextval",
region CONSTANT '',
time_loaded "to_char(SYSDATE, 'HH24:MI')",
data1 POSITION(1:5) ":data1/100",
data2 POSITION(6:15) "upper(:data2)",
data3 POSITION(16:22)"to_date(:data3, 'YYMMDD')"
)
BEGINDATA
11111AAAAAAAAAA991201
22222BBBBBBBBBB990112

可以将多个文件导入到同一个表或者多个表中

load data
infile t1.dat
infile t2.dat
infile t3.dat
append into table student
(SNAME position(:),
SAGE position(:) ,
SEMAIL position(:),
SPHONE position(:),
SADDRESS position(:)
)

这里有很多命令的解释

这里有很多问题的回答(FAQ

简单实现几个例子,稍后有时间添加多点理论知识,再边学习边完善了。

Oracle Sql Loader的学习使用的更多相关文章

  1. [Oracle] SQL*Loader 详细使用教程(2)- 命令行参数

    sqlldr工具   SQL*Loader的客户端工具是sqlldr,在操作系统的命令行下输入sqlldr,后面不接任何参数,将显示帮助信息如下所示(所有命令行参数的简单描述及其默认值),所以你并不需 ...

  2. [Oracle] SQL*Loader 详细使用教程(3)- 控制文件

    控制文件是SQL*Loader里最重要的文件,它是一个文本文件,用来定义数据文件的位置.数据的格式.以及配置数据加载过程的行为,在sqlldr中以control参数指定控制文件.   在控制文件里配置 ...

  3. [Oracle] SQL*Loader 详细使用教程(1)- 总览

    SQL*Loader原理   SQL*Loader是Oracle提供的用于数据加载的一种工具,它比较适合业务分析类型数据库(数据仓库),能处理多种格式的平面文件,批量数据装载比传统的数据插入效率更高. ...

  4. [Oracle] SQL*Loader 详细使用教程(4)- 字段列表

    在上一篇中我们介绍了SQL*Loader中最重要的文件——控制文件,而本篇要介绍控制文件中最重要的部分——字段列表,字段列表的作用是把数据文件中的记录和数据库中表的列对应起来,下面是字段列表的一个例子 ...

  5. Oracle SQL Loader

    C:/Documents and Settings/WWJD>sqlldr SQL :: Copyright (c) , , Oracle. All rights reserved. 用法: S ...

  6. Oracle SQL*Loader commit point tips

    http://www.dba-oracle.com/t_sql_loader_commit_frequency.htm - Question:  Can I control the commit fr ...

  7. [Oracle] SQL*Loader 详细使用教程(5)- 典型例子

    本文介绍SQL*Loader在实际使用过程中经常用到的典型例子. 1. 表中的列比数据文件的列要少怎么办? 假设一个csv的文件如下: a1,a2,a3,a4 b1,b2,b3,b4 c1,c2,c3 ...

  8. Oracle SQL*Loader 数据导入工具

    SQL*Loader是一个向Orale大量倒数据的工具,可以从界定文件中导入数据如用 , 界定的,可以从定宽的文件导入数据,

  9. Oracle SQL优化进阶学习

    引言 对于下面的Oracle分页如何优化该段语句: SELECT * FROM (SELECT A.*, ROWNUM RN FROM (SELECT * FROM task_log order by ...

随机推荐

  1. iOS关于直播的链接

    iOS关于直播集成的链接 http://www.jianshu.com/p/7b2f1df74420 https://www.cnblogs.com/graveliang/p/5683617.html ...

  2. _quest_mod

    该功能实现对任务的优化,设定接受任务的条件,比如VIP等级几或者军衔多少持有何种物品才可以接受任务,同时可以配置任务的随机奖励及几率,以上修改都会在任务文本中体现.还支持任务传送功能,接完任务后,可和 ...

  3. ABP权限认证

    通过AOP+特性实现 ABP默认的权限验证过滤器 AbpAuthorizationFilter   可以通过继承AsyncAuthorizationFilter 自定义自己的权限过滤器 权限数据存放表 ...

  4. adt安装----只为测试使用adb命令,故无需安装过于复杂

    下载并安装Android SDK  借鉴自原文 https://blog.csdn.net/qq_15304853/article/details/79168248 官网(可FQ选择):http:// ...

  5. selenium + firefox驱动版本对应。

    1)selenium 2.51.0====firefox 46 selenium 3.11.0 ====firefox 56 后来发现最新的火狐浏览器好多插件都不能用了.所以果断回到46.对应的2.5 ...

  6. sevrlet进行用户名密码校验

    在eclipse中建立了web项目,实现注册和登录还有在个人中心显示用户名密码 注册功能 源码如下 package com.sevlet.demo; import java.io.IOExceptio ...

  7. Django框架(二)

    四.Django简介 1.MVC与MTV模型 MVC Web服务器开发领域里著名的MVC模式,所谓MVC就是把Web应用分为模型(M),控制器(C)和视图(V)三层,他们之间以一种插件式的.松耦合的方 ...

  8. vs2013打包安装程序

    安装扩展包Visual Studio Installer VS2013下默认是没有Visual Studio Installer的,需要安装对应的扩展包: 下载地址:VS2013安装向导扩展包下载 安 ...

  9. Android 音视频深入 九 FFmpeg解码视频生成yuv文件(附源码下载)

    项目地址,求star https://github.com/979451341/Audio-and-video-learning-materials/tree/master/FFmpeg(MP4%E8 ...

  10. 错误:Bean property 'sessionFactory' is not writable or has an invalid setter method.

    Caused by: org.springframework.beans.NotWritablePropertyException: Invalid property 'sessionFactory' ...