Chinaunix首页 | 论坛 | 博客
  • 博客访问: 213372
  • 博文数量: 57
  • 博客积分: 1376
  • 博客等级: 中尉
  • 技术积分: 658
  • 用 户 组: 普通用户
  • 注册时间: 2010-05-09 09:51
文章分类

全部博文(57)

文章存档

2012年(1)

2011年(56)

分类: Oracle

2012-01-18 18:04:48

简而言之, fix告诉每次取一行的范围, 然后,通过看这一行相应的分隔符去分开对应字段中的数据。
而var的意思是,数据前多少位代表后面多少bytes算成一行,然后再在这一行中做分割。


举例:
1. fix的例子:

  1. [oracle@rac1 sqlldr]$ cat ctl1.txt
  2. load data
  3. infile 'example1.dat' "fix 8"
  4. truncate into table t2
  5. fields terminated by ',' optionally enclosed by '"'
  6. (name1 ,
  7. name2 )
  8. [oracle@rac1 sqlldr]$ sqlldr milo/milo control=ctl1.txt

  9. SQL*Loader: Release 10.2.0.4.0 - Production on Wed Jan 18 17:09:20 2012

  10. Copyright (c) 1982, 2007, Oracle. All rights reserved.

  11. Commit point reached - logical record count 6
  12. SQL*Loader-501: Unable to read file (example1.dat)
  13. SQL*Loader-566: partial record found at end of datafile ===》 因为,发现有不符合规定的记录,例如取到的数据没有找到分隔符。
  14. SQL*Loader-2026: the load was aborted because SQL Loader cannot continue.


结果:
  1. SQL> select * from t2;

  2. NAME1 NAME2
  3. ----- -------
  4. 001 c
  5. d 0002
  6. fghi 00
  7. 03 mn

分析:
数据如下:
  1. [oracle@rac1 sqlldr]$ cat example1.dat
  2. 001, cd, 0002,fghi,
  3. 0003,mn,1, "pqrs",abc
  4. 0005,uvwx,


===》 因为是"fix 8",每次取8个bytes作为一行
=====》 1. 取到“001,   c” , 然后以","作为字段的分割,那么,结果插入的就是"001","c",开头的空格会被去掉。

=====》 2. 取到"d, 0002," , 然后以","作为字段分割, 那么,结果插入的就是"d","0002",相当于这一行分割了3个字段,因为有两个","。

"fghi,\n00" ====> 
"03,mn,1," ====>
"pqrs"," ====> 扫到这的时候,就有问题了。分割符后没有数据,之内能插入一个字段的数据。

所以报错SQL*Loader-566: partial record found at end of datafile。


  1. SQL*Loader-00566: partial record found at end of datafile

  2.     Cause:
  3.     An incomplete record was found at the end of file.
  4.     Action:
  5.     Make sure the last record in the datafile is complete and has the correct terminating character(s).


2. var的例子1:

var其实就是每次开头告诉sqlldr每行变化取多少位,相当于每次都指定个fix多少(由前面的数据决定位数)的值。这也就是变长的做法。

  1. 009hello,cd,010world,im,

  2. 012my,name is,

===》 例如这个是"var 3",也就是告诉sqlldr前3位数字是fix多少的参数。
  1. [oracle@rac1 sqlldr]$ cat ctl.txt
  2. load data
  3. infile 'example.dat' "var 3"
  4. truncate into table t1
  5. fields terminated by ',' -- optionally enclosed by '"'
  6. (name1 char(5),
  7.  name2 char(7))


  8. [oracle@rac1 sqlldr]$ cat example.dat
  9. 009hello,cd1
  10. 010world,im,
  11. 012my,name is,

在这种情况会报错:
  1. [oracle@rac1 sqlldr]$ sqlldr milo/milo control=ctl.txt

  2. SQL*Loader: Release 10.2.0.4.0 - Production on Wed Jan 18 17:40:43 2012

  3. Copyright (c) 1982, 2007, Oracle. All rights reserved.

  4. SQL*Loader-501: Unable to read file (example.dat)
  5. SQL*Loader-563: bad length for VAR record
  6. SQL*Loader-509: System error: Error 0
  7. SQL*Loader-2026: the load was aborted because SQL Loader cannot continue.


第一次,根据前面的"009"确认要在之后去9bytes,取到”hello,cd1“; 第二次,确认去多少行的时候,通过"\n00"发现有非数字数据,因此,确认不了后面的取多少位。因此报错。 报错563里也说明得很清楚:包含有非数字的数据。
  1. SQL*Loader-00563: bad length for VAR record

  2. Cause:
  3. The length protion of a VAR record contains non-numeric data.
  4. Action:
  5. Fix the data in the file.



3. var的例子2:


  1. [oracle@rac1 sqlldr]$ cat example.dat
  2. 009hello,cd1010world,im,
  3. 012my,name is,

  4. [oracle@rac1 sqlldr]$ cat ctl.txt
  5. load data
  6. infile 'example.dat' "var 3"
  7. truncate into table t1
  8. fields terminated by ',' -- optionally enclosed by '"'
  9. (name1 char(5),
  10. name2 char(7))


  1. [oracle@rac1 sqlldr]$ sqlldr milo/milo control=ctl.txt

  2. SQL*Loader: Release 10.2.0.4.0 - Production on Wed Jan 18 17:54:25 2012

  3. Copyright (c) 1982, 2007, Oracle. All rights reserved.

  4. Commit point reached - logical record count 3



结果如下:
  1. SQL> select *from t1;

  2. NAME1 NAME2
  3. ----- -------
  4. hello cd1
  5. world im
  6. my    name is


分析:
====> 第一次取数字,取到"009",也就是取到009的后面9位。取到"hello,cd1",插入"hello","cd1"
====> 第二次取数字,取到"010",也就是取到010的后面10位。取到"world,im,\n",插入数据"world","im",换行也被去掉。
====> 第三次取数字,取到"012",也就是取到012的后面12位。取到"my,name is,\n",插入数据"my","name is",后面的第三个字段内容忽略。

阅读(5536) | 评论(1) | 转发(1) |
0

上一篇:小patch(psu)的打法 -- 实例

下一篇:没有了

给主人留下些什么吧!~~

马夹GG2012-01-21 00:34:37

想起了PASCAL中的VAR是定义变量的保留字啊,好怀念!