sqlldr只将字符串的第一个字符加载到列中

时间:2018-02-22 22:14:35

标签: oracle sql-loader

我正在尝试使用sqlldr将数据加载到数据库表中。 我遇到的问题是只加载了每一行的第一个字符。 我在AIX上使用Oracle版本12.1。 我的数据是单列文本文件。 每条记录的长度都是可变的。 在此测试集中,我们将数据限制为10个字符。 每行都在一个新行上。 它应该加载到单个列表中。

我的空表定义为:

create table test_table (test_num varchar2(10));

我的数据看起来像没有双重间距:

3675536758

8370530737

9318078

5395653669

查看od -c中的数据,看起来像是:

0000000    3   6   7   5   5   3   6   7   5   8  \n   8   3   7   0   5
0000020    3   0   7   3   7  \n   9   3   1   8   0   7   8  \n   5   3
0000040    9   5   6   5   3   6   6   9  \n
0000051

我的控制文件如下:

load data
 infile 'test.txt' "str '\n'"
 into TABLE test_table
 (test_num char "trim(:test_num)")

我遇到的问题只是每行加载到表格中的第一个字符。

此行为在有或没有修剪功能且有或没有"str '\n'"

的情况下仍然存在

任何建议都将不胜感激。

2 个答案:

答案 0 :(得分:3)

(test_num char "trim(:test_num)")修改为(test_num char(10) "trim(:test_num)"),记录将按预期加载。

char将是一个字符,而char(10)将是10个字符。

在Windows服务器上,我将控制文件更改为不使用流记录格式(不是问题的根源)。

load data
 infile * 
 into TABLE test_table
 (test_num char(10) "trim(:test_num)")
BEGINDATA
3675536758
8370530737
9318078
5395653669

enter image description here

我们现在看到这些记录:

SCOTT@erptst>select * from test_table;
TEST_NUM
3675536758
8370530737
9318078
5395653669

答案 1 :(得分:0)

或者,terminated by whitespace可能有所帮助:

load data
infile * 
replace
into table test_table
(test_num  terminated by whitespace
)
begindata
3675536758
8370530737
9318078
5395653669

加载会话&结果:

SQL> $sqlldr scott/tiger@orclcontrol=test23.ctl

SQL*Loader: Release 11.2.0.2.0 - Production on Pet Vel 23 07:45:32 2018

Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.

Commit point reached - logical record count 3
Commit point reached - logical record count 4

SQL> select * from test_table;

TEST_NUM
----------
3675536758
8370530737
9318078
5395653669

SQL>
相关问题