Oracle Sql Loader的学习使用
最近由于遇到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(:)
)
这里有很多命令的解释
简单实现几个例子,稍后有时间添加多点理论知识,再边学习边完善了。
Oracle Sql Loader的学习使用的更多相关文章
- [Oracle] SQL*Loader 详细使用教程(2)- 命令行参数
sqlldr工具 SQL*Loader的客户端工具是sqlldr,在操作系统的命令行下输入sqlldr,后面不接任何参数,将显示帮助信息如下所示(所有命令行参数的简单描述及其默认值),所以你并不需 ...
- [Oracle] SQL*Loader 详细使用教程(3)- 控制文件
控制文件是SQL*Loader里最重要的文件,它是一个文本文件,用来定义数据文件的位置.数据的格式.以及配置数据加载过程的行为,在sqlldr中以control参数指定控制文件. 在控制文件里配置 ...
- [Oracle] SQL*Loader 详细使用教程(1)- 总览
SQL*Loader原理 SQL*Loader是Oracle提供的用于数据加载的一种工具,它比较适合业务分析类型数据库(数据仓库),能处理多种格式的平面文件,批量数据装载比传统的数据插入效率更高. ...
- [Oracle] SQL*Loader 详细使用教程(4)- 字段列表
在上一篇中我们介绍了SQL*Loader中最重要的文件——控制文件,而本篇要介绍控制文件中最重要的部分——字段列表,字段列表的作用是把数据文件中的记录和数据库中表的列对应起来,下面是字段列表的一个例子 ...
- Oracle SQL Loader
C:/Documents and Settings/WWJD>sqlldr SQL :: Copyright (c) , , Oracle. All rights reserved. 用法: S ...
- Oracle SQL*Loader commit point tips
http://www.dba-oracle.com/t_sql_loader_commit_frequency.htm - Question: Can I control the commit fr ...
- [Oracle] SQL*Loader 详细使用教程(5)- 典型例子
本文介绍SQL*Loader在实际使用过程中经常用到的典型例子. 1. 表中的列比数据文件的列要少怎么办? 假设一个csv的文件如下: a1,a2,a3,a4 b1,b2,b3,b4 c1,c2,c3 ...
- Oracle SQL*Loader 数据导入工具
SQL*Loader是一个向Orale大量倒数据的工具,可以从界定文件中导入数据如用 , 界定的,可以从定宽的文件导入数据,
- Oracle SQL优化进阶学习
引言 对于下面的Oracle分页如何优化该段语句: SELECT * FROM (SELECT A.*, ROWNUM RN FROM (SELECT * FROM task_log order by ...
随机推荐
- 调研IOS的开发环境的发展演变
一. 关于IOS的开发发展历史: 百度一下,关于这方面的详细资料有很多,在这里就不复制粘贴占用篇幅了. 二. 关于个人搭建IOS开发环境的体验: 本人用的是华硕电脑,window7的操作系统,本来为了 ...
- adt安装----只为测试使用adb命令,故无需安装过于复杂
下载并安装Android SDK 借鉴自原文 https://blog.csdn.net/qq_15304853/article/details/79168248 官网(可FQ选择):http:// ...
- postman(五):在不同接口之间传递数据
为了更灵活地构造请求以及处理响应数据,postman提供了Pre-request-Script和Tests,在这两个标签中可以编写js代码辅助测试.之前学习了在发送请求的Tests标签如何添加断言以及 ...
- flink入门
wordCount POM文件需要导入的依赖: <dependency> <groupId>org.apache.flink</groupId> <artif ...
- Log4Net 添加自定义字段并保存到数据库
Log4Net是常用的功能强大的日志插件,该插件提供了几个默认字段 大家可能都用过Log4Net插件来记录日志,该插件默认提供了这几个字段@log_date, @thread, @log_level, ...
- python学习(十)
- 【其他】【http】【1】HTTP状态码
一些常见的状态码: 200 - 服务器成功返回网页 400 - 错误请求 404 - 请求的网页不存在 500 - 服务器内部错误 503 - 服务器超时 状态码大全: 1xx(临时响应)表示临时响应 ...
- js创建对象的三种方法
1.使用对象初始化器:{} var person = {....} 2 var person=new object() function person(参数) { this.参数=... } var ...
- PAMIE模块安装
PAMIE2.0适用于python2.0.x,PAMIE3.0适用于python3.0.x. 这里记录安装PAMIE2.0方法: 一.安装PAMIE2.0 1.下载PAMIE20压缩包:https:/ ...
- kafka producer 发送消息简介
kafka 的 topic 由 partition 组成,producer 会根据 key,选择一个 partition 发送消息,而 partition 有多个副本,副本有 leader 和 fol ...