免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 977 | 回复: 0
打印 上一主题 下一主题

SQLLDR使用小结(下) [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-06-12 23:09 |只看该作者 |倒序浏览
7 ***** 合并多行记录为一行记录  
LOAD DATA  
INFILE *  
concatenate 3 // 通过关键字concatenate 把几行的记录看成一行记录  
INTO TABLE DEPT  
replace  
FIELDS TERMINATED BY ','  
(DEPTNO,  
DNAME "upper(:dname)",  
LOC "upper(:loc)",  
LAST_UPDATED date 'dd/mm/yyyy'  
)  
BEGINDATA  
10,Sales, // 其实这3行看成一行 10,Sales,Virginia,1/5/2000  
Virginia,  
1/5/2000  
// 这列子用 continueif list="," 也可以  
告诉sqlldr在每行的末尾找逗号 找到逗号就把下一行附加到上一行  
  
LOAD DATA  
INFILE *  
continueif this(1:1) = '-' // 找每行的开始是否有连接字符 - 有就把下一行连接为一行  
// 如 -10,Sales,Virginia,  
// 1/5/2000 就是一行 10,Sales,Virginia,1/5/2000  
// 其中1:1 表示从第一行开始 并在第一行结束 还有continueif next 但continueif list最理想  
INTO TABLE DEPT  
replace  
FIELDS TERMINATED BY ','  
(DEPTNO,  
DNAME "upper(:dname)",  
LOC "upper(:loc)",  
LAST_UPDATED date 'dd/mm/yyyy'  
)  
BEGINDATA // 但是好象不能象右面的那样使用  
-10,Sales,Virginia, -10,Sales,Virginia,  
1/5/2000 1/5/2000  
-40, 40,Finance,Virginia,13/04/2001  
Finance,Virginia,13/04/2001
  
8 ***** 载入每行的行号  
  
load data  
infile *  
into table t  
replace  
( seqno RECNUM //载入每行的行号  
text Position(1:1024))  
BEGINDATA  
fsdfasj //自动分配一行号给载入 表t 的seqno字段 此行为 1  
fasdjfasdfl // 此行为 2 ...  
9 ***** 载入有换行符的数据  
注意: unix 和 windows 不同 \\n & /n  
使用一个非换行符的字符  
LOAD DATA  
INFILE *  
INTO TABLE DEPT  
REPLACE  
FIELDS TERMINATED BY ','  
TRAILING NULLCOLS  
(DEPTNO,  
DNAME "upper(:dname)",  
LOC "upper(:loc)",  
LAST_UPDATED "my_to_date( :last_updated )",  
COMMENTS "replace(:comments,'\n',chr(10))" // replace 的使用帮助转换换行符  
)  
BEGINDATA  
10,Sales,Virginia,01-april-2001,This is the Sales\nOffice in Virginia  
20,Accounting,Virginia,13/04/2001,This is the Accounting\nOffice in Virginia  
30,Consulting,Virginia,14/04/2001 12:02:02,This is the Consulting\nOffice in Virginia  
40,Finance,Virginia,987268297,This is the Finance\nOffice in Virginia  
  
使用fix属性  
LOAD DATA  
INFILE demo17.dat "fix 101"  
INTO TABLE DEPT  
REPLACE  
FIELDS TERMINATED BY ','  
TRAILING NULLCOLS  
(DEPTNO,  
DNAME "upper(:dname)",  
LOC "upper(:loc)",  
LAST_UPDATED "my_to_date( :last_updated )",  
COMMENTS  
)  
demo17.dat  
10,Sales,Virginia,01-april-2001,This is the Sales  
Office in Virginia  
20,Accounting,Virginia,13/04/2001,This is the Accounting  
Office in Virginia  
30,Consulting,Virginia,14/04/2001 12:02:02,This is the Consulting  
Office in Virginia  
40,Finance,Virginia,987268297,This is the Finance  
Office in Virginia  
  
// 这样装载会把换行符装入数据库 下面的方法就不会 但要求数据的格式不同  
LOAD DATA  
INFILE demo18.dat "fix 101"  
INTO TABLE DEPT  
REPLACE  
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'  
TRAILING NULLCOLS  
(DEPTNO,  
DNAME "upper(:dname)",  
LOC "upper(:loc)",  
LAST_UPDATED "my_to_date( :last_updated )",  
COMMENTS  
)  
demo18.dat  
10,Sales,Virginia,01-april-2001,"This is the Sales  
Office in Virginia"  
20,Accounting,Virginia,13/04/2001,"This is the Accounting  
Office in Virginia"  
30,Consulting,Virginia,14/04/2001 12:02:02,"This is the Consulting  
Office in Virginia"  
40,Finance,Virginia,987268297,"This is the Finance  
Office in Virginia"  
  
使用var属性  
LOAD DATA  
INFILE demo19.dat "var 3"  
// 3 告诉每个记录的前3个字节表示记录的长度 如第一个记录的 071 表示此记录有 71 个字节  
INTO TABLE DEPT  
REPLACE  
FIELDS TERMINATED BY ','  
TRAILING NULLCOLS  
(DEPTNO,  
DNAME "upper(:dname)",  
LOC "upper(:loc)",  
LAST_UPDATED "my_to_date( :last_updated )",  
COMMENTS  
)  
demo19.dat  
07110,Sales,Virginia,01-april-2001,This is the Sales  
Office in Virginia  
07820,Accounting,Virginia,13/04/2001,This is the Accounting  
Office in Virginia  
08730,Consulting,Virginia,14/04/2001 12:02:02,This is the Consulting  
Office in Virginia  
07140,Finance,Virginia,987268297,This is the Finance  
Office in Virginia  
  
使用str属性  
// 最灵活的一中 可定义一个新的行结尾符 win 回车换行 : chr(13)||chr(10)  
此列中记录是以 a|\r\n 结束的  
select utl_raw.cast_to_raw('|'||chr(13)||chr(10)) from dual;  
结果 7C0D0A  
  
LOAD DATA  
INFILE demo20.dat "str X'7C0D0A'"  
INTO TABLE DEPT  
REPLACE  
FIELDS TERMINATED BY ','  
TRAILING NULLCOLS  
(DEPTNO,  
DNAME "upper(:dname)",  
LOC "upper(:loc)",  
LAST_UPDATED "my_to_date( :last_updated )",  
COMMENTS  
)  
demo20.dat  
10,Sales,Virginia,01-april-2001,This is the Sales  
Office in Virginia|  
20,Accounting,Virginia,13/04/2001,This is the Accounting  
Office in Virginia|  
30,Consulting,Virginia,14/04/2001 12:02:02,This is the Consulting  
Office in Virginia|  
40,Finance,Virginia,987268297,This is the Finance  
Office in Virginia|  
  
==============================================================================  
象这样的数据 用 nullif 子句  
  
10-jan-200002350Flipper seemed unusually hungry today.  
10510-jan-200009945Spread over three meals.  
  
id position(1:3) nullif id=blanks // 这里可以是blanks 或者别的表达式  
// 下面是另一个列子 第一行的 1 在数据库中将成为 null  
LOAD DATA  
INFILE *  
INTO TABLE T  
REPLACE  
(n position(1:2) integer external nullif n='1',  
v position(3:8)  
)  
BEGINDATA  
1 10  
20lg  
------------------------------------------------------------  
  
如果是英文的日志 格式,可能需要修改环境变量 nls_lang or nls_date_format


本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u2/71105/showart_973719.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP