如何验证控制文件中的数据?
考虑 SQLLoader 从路径读取输入数据文件,并根据控制文件中指定的描述将数据加载到表中。 首先,创建要填充的表:
create table sql_loader_1 ( load_time date, field_1 Numeric, field_2 varchar2(10)
示例控制文件: load_1.ctl
load data
infile 'load_1.dat' "str '\r\n'"
insert into table sql_loader_1
(
load_time sysdate,
field_2 position( 1:10),
field_1 position(11:20)
)
请注意,位置 11 到 20 加载到 field_1 中,位置 1 到 10 加载到 field_2 中。字段 load_time 填充负载的当前时间(sysdate)。
这是数据。文件名 (load_1.dat) 已通过控制文件中的 infile 语句指定。
load_1.dat
0123456789abcdefghij
**********##########
foo bar
here comes a very long line
and the next is
short
这里我想验证 field_1 (数字数据类型),因为数据文件包含字符值(即)abcdefghij
Consider that the SQLLoader reads the Input data File from the path and it loads the data into the tables based up on the descrition specified in the control File.
First, the table to be filled is created:
create table sql_loader_1 ( load_time date, field_1 Numeric, field_2 varchar2(10)
Sample Control File :
load_1.ctl
load data
infile 'load_1.dat' "str '\r\n'"
insert into table sql_loader_1
(
load_time sysdate,
field_2 position( 1:10),
field_1 position(11:20)
)
Note that the positions 11 through 20 are loaded into field_1 and positions 1 through 10 into field_2. The field load_time is filled with the current time (sysdate) of the load.
Here's the data. The name of the file (load_1.dat) had been specified with the infile statement in the control file.
load_1.dat
0123456789abcdefghij
**********##########
foo bar
here comes a very long line
and the next is
short
Here I want to validate the field_1 (Numeric Datatype) since the data file contains the character value (i.e)abcdefghij
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您说您想要验证 field_1,但不清楚如果验证失败您期望采取什么操作?
另外两个想法:
您是否考虑过在控制文件中使用 BADFILE 选项来处理被拒绝的行?
不要在 SQL-Loader 中处理数字转换,而是以文本形式加载数据并将其转换为数字/在数据库中处理一次。这可能会更容易。
You say you want to validate field_1, but it's not clear what action are you expecting if the validation fails?
Two other thoughts:
Have you considered using the BADFILE option in your control file for rejected rows?
Instead of dealing with the number conversion in SQL-Loader, load the data as text and convert it to a number/handle it once in the database. This may be easier.