注:调用中必须用n来表示替换符,而不是n
2)在infile指令上使用FIX属性,加载一个定长平面文件。
使用该方法,输入数据必须出现在定长记录中。对于固定位置的数据,使用FIX属性就特别合适,这些文件一般为定长文件。
另外使用该方法时,数据必须在外部存储,不能存储在控制文件本身。
--控制文件
load data
infile demo.dat "fix 80" --指定了输入数据文件demo.dat,这个文件中每个记录80字节
into table dept
replace
fields terminated by ','
trailing nullcols
(deptno,
dname "upper(:dname)",
loc "upper(:loc)",
comments
)
--数据文件
10,Sales,Virginia,this is the salesnoffice in Virginia
20,,,Sales,Virginia,this is the salesnoffice in Virginia 注:
在unix上,行结束标记是n即CHR(10),而windows nt平台的行结束标记是rn即CHR(13)||CHR(10);
可以在控制文件中使用trim内置sql函数来完成截断尾部的空白符
select * from dept;3)在infile指令在、上使用VAR属性,加载一个变宽文件,在该文件使用的格式中,每一行前几个字节指定了这一行的长度
--控制文件
load data
infile demo.dat "var 3" --表明了前三个字节用于记录每一行的字节数
into table dept
replace
fields terminated by ','
trailing nullcols
(deptno,
dname "upper(:dname)",
loc "upper(:loc)",
comments
)
--数据文件
05410,Sales,Virginia,this is the sales office in Virginia注:在unix上换行符只算一个字节,在windows nt上算两个字节
select * from dept;4)在infile指令上使用STR属性,加载一个变宽文件,其中用某个字符序列来表示行结束符,而不是用换行符表示
STR属性以十六进制指定,要得到十六进制串,最容易的办法就是使用sql和utl_raw来生成十六进制串。如在unix平台,行结束标记是CHR(10),我们的特殊字符是一个管道符号(|),则可以写成:
select utl_raw.cast_to_raw('|'||chr(10)) from dual;--可见在unix上为x'7C0A'在windows上用
select utl_raw.cast_to_raw('|'||chr(13)||chr(10)) from dual;--为x'7C0D0A'
--控制文件
load data
infile demo.dat "str x'7C0D0A'"
into table dept
replace
fields terminated by ','
trailing nullcols
(deptno,
dname "upper(:dname)",










