分类: Oracle
2010-12-17 12:33:14
SQL Loader
方式一:控制文件,数据在文件控制文件之外
1>控制文件
load data --控制文件标识
INFILE '/u02/sqlloader/test.dat' --要输入的数据文件名为test.dat
append
into table tb --向表tb中追加记录
fields terminated by ',' --字段终止于',',
--fields terminated by "," optionally enclosed by '"'
--optionally
(
id1,id2
) --定义列对应顺序
注解:
insert,为缺省方式,在数据装载开始时要求表为空
append,在表中追加新记录
replace,删除旧记录,替换成新装载的记录
truncate,同上
2>数据文件
[oracle@node2 sqlloader]$ cat test.dat
1,2
3,4
5,6
7,8
3>数据库上的操作
--在system用户下
SQL> conn system/hellojin
Connected.
--建表
SQL> create table tb(id1 number ,id2 number) ;
Table created.
SQL> select count(*) from tb;
COUNT(*)
----------
0
4>执行
SQL> !
[oracle@node2 ~]$ sqlldr userid=system/hellojin control=/u02/sqlloader/control.ctl
SQL*Loader: Release 10.2.0.1.0 - Production on Wed Dec 8 23:53:41 2010
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Commit point reached - logical record count 5
[oracle@node2 ~]$ exit
exit
SQL> select * from tb;
ID1 ID2
---------- ----------
1 2
3 4
5 6
7 8
方式二:控制文件,数据也在控制文件之内
1>控制文件
LOAD DATA
INFILE *
append
into table tb
fields terminated by ','
(
id1,id2
)
Begindata
1,2
3,4
5,6
7,8
2>执行
[oracle@node2 ~]$ sqlldr userid=system/hellojin control=/u02/sqlloader/control2.ctl
SQL> select * from tb ;
ID1 ID2
---------- ----------
1 2
3 4
5 6
7 8
1 2
3 4
5 6
7 8
8 rows selected.
---------------------------
遇到的问题
1>加载的数据包含分隔符
1optionally enclosed by
2>数据文件没有分隔符
A B C
D E F
--
保存为test.dat
定长字符串
Load data
Infile test.dat
Truncate into table bonus
(
Name1 position(1:5),
Name2 position(7:15),
Name3 position(17:20)
)
3>数据文件中的列比要导入的表中列少
Load data
Infile test.dat
Truncate into table bonus
(
Name1 position(1:5),
Name2 position(7:15),
Name3 position(17:20),
Comm "0" --无数据的列
)
4>数据文件中的列比要导入的表中列多
方式1:
修改数据文件,删除多余的列
方式2:
Load data
Infile test.dat
Truncate into table bonus
(
Name1 position(1:5),
Name2 position(7:15),
Name3 position(17:20),
Tcol filler position(21:28)
)
--控制文件中对列定义时指出filler关键字,可以用来指定过滤列
--相当于8-11之间不导入
--filler 关键字,用来指定过滤列
5>提供多个数据文件,要导入同一张表
提供的数据文件中的数据存放格式必须完全相同
Load data
Infile test1.dat
Infile test2.dat
Infile test3.dat
Infile test4.dat
Truncate into table bonus
(
Id1,
Id2
)
6>同一个数据文件,要导入不同表
load data
Infile test.dat
discardfile discard.dsc
Truncate
Into table bonus when tab='bon'
(
Tab filler position (1:3),
Ename position (5:9)
)
Into table manager
When tab = 'mgr'
(
Table filler position(1:3),
Ename position (4:5)
)
7>数据文件前N行不导入
[oracle@node2 ~]$ sqlldr scott/tiger control=control.ctl skip=3
还有个load参数
8>手工指定的换行符
略
chinaunix网友2011-06-05 01:59:22
大连法律咨询在线 http://www.fabowang.com 大连律师在线咨询 http://www.fabowang.com 大连法律顾问网 http://www.fabowang.com 大连律师咨询 http://www.fabowang.com
chinaunix网友2010-12-26 10:18:34
牌技 | 牌技手法 | 牌技教学 | 牌技培训 | 透视眼镜 赌俱高科 最新产品 牌九二八杠 面授培训 扑克麻将 面授培训 牌技光盘 函授培训 出场代理 洗牌绝技 发牌绝技 摸牌绝技 变牌绝技■●■扑克麻将出老千术牌技视频教学光盘 每盘8元货到付款 省心防骗 150O-6565-675 您一个订货电-话,通知地址姓名,我们立刻免费发货,送货到你家时再一手交钱一手交货。 订货电-话 壹伍零零陆伍 陆伍陆柒伍第一套10碟★赌博千术大揭秘第二套12碟★扑克牌技麻将技巧千术破解第三套 9碟★扑克麻将高科技牌具老千揭秘第四套10碟★扑克麻将绝技千术揭秘 扑克麻将牌技共42盘VCD,讲42小时,货到付款 省心防骗 电-话15OO65-65675★●★中国扑克麻将牌技培训网 http://pkmjyd.blog.163.com/联系手机:15OO-6565-675 地址:上海市黄浦区南京路6号 每碟8元 货到付款 省心防骗 ,特快专递,送货上门,全国三天到货。你只需打一个订货电-话,告诉我们你的收货地址姓名,我们立刻发货,三天后送到家中再付款。货到付款 是对我们商品和服务质量的一种无言的承诺,请您放
chinaunix网友2010-12-17 19:08:56
很好的, 收藏了 推荐一个博客,提供很多免费软件编程电子书下载: http://free-ebooks.appspot.com