混合固定长度和可变长度字段的 SQLLDR

发布于 2025-01-08 03:30:17 字数 1366 浏览 1 评论 0原文

我正在尝试加载一个包含如下记录的示例数据文件:

12312^123456^0015GRAJ1M7J0002^SOME GIBBERISH                    ^123

我需要将这 5 个字段与 6 个数据库列相关联,其中第一个记录分为 2 个:

'12312' -> '123' 和 '12'

以及其余字段以“^”分隔。

我现在所拥有的是:

    COL_ONE POSITION(1:3) INTEGER EXTERNAL,
    COL_TWO POSITION(4:5) CHAR TERMINATED BY "^",
    COL_THREE INTEGER EXTERNAL TERMINATED BY "^",
    COL_FOUR CHAR TERMINATED BY "^",
    COL_FIVE CHAR TERMINATED BY "^",
    COL_SIX CHAR TERMINATED BY "^"
    ....

但这并不能按预期工作,因为由于某种原因字段

"SOME GIBBERISH                    "

最终被插入到 COL_SIX 而不是 COL_FIVE 中,这给了我一个错误。

我的日志显示:

   Column Name                  Position   Len  Term Encl Datatype
------------------------------ ---------- ----- ---- ---- ---------------------
COL_ONE                               1:3     3           CHARACTER            
COL_TWO                               4:5     2   ^       CHARACTER            
COL_THREE                            NEXT     *   ^       CHARACTER            
COL_FOUR                             NEXT     *   ^       CHARACTER            
COL_FIVE                             NEXT     *   ^       CHARACTER            
COL_SIX                              NEXT     *   ^       CHARACTER

任何帮助将不胜感激。

I'm trying to load an example datafile with records like this:

12312^123456^0015GRAJ1M7J0002^SOME GIBBERISH                    ^123

I need to associate this 5 fields with 6 database columns, where the first record is broken into 2:

'12312' -> '123' and '12'

and the rest of the fields are "^" separated.

What I have now is:

    COL_ONE POSITION(1:3) INTEGER EXTERNAL,
    COL_TWO POSITION(4:5) CHAR TERMINATED BY "^",
    COL_THREE INTEGER EXTERNAL TERMINATED BY "^",
    COL_FOUR CHAR TERMINATED BY "^",
    COL_FIVE CHAR TERMINATED BY "^",
    COL_SIX CHAR TERMINATED BY "^"
    ....

but this doesn't work as expected as for some reason field

"SOME GIBBERISH                    "

ends up being inserted in COL_SIX instead of COL_FIVE, which gives me an error.

My log shows:

   Column Name                  Position   Len  Term Encl Datatype
------------------------------ ---------- ----- ---- ---- ---------------------
COL_ONE                               1:3     3           CHARACTER            
COL_TWO                               4:5     2   ^       CHARACTER            
COL_THREE                            NEXT     *   ^       CHARACTER            
COL_FOUR                             NEXT     *   ^       CHARACTER            
COL_FIVE                             NEXT     *   ^       CHARACTER            
COL_SIX                              NEXT     *   ^       CHARACTER

any help would be highly appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

难如初 2025-01-15 03:30:17

好的,通过尝试和错误解决了问题:

COL_ONE POSITION(1:3) INTEGER EXTERNAL,
COL_TWO CHAR TERMINATED BY "^",
.....

Ok, problem solved with trial and error:

COL_ONE POSITION(1:3) INTEGER EXTERNAL,
COL_TWO CHAR TERMINATED BY "^",
.....
吹泡泡o 2025-01-15 03:30:17

问题来自您的第三个字段:

COL_THREE INTEGER EXTERNAL TERMINATED BY "^"

该字段从位置 6 开始,不幸的是,该字段包含 ^ 因此该字段将填充 NULL 值,将所有后续字段推入错误的列。

您可以使用 填充符 来忽略 <位置 6 处的 code>^ 字符:

COL_ONE POSITION(1:3) INTEGER EXTERNAL,
COL_TWO POSITION(4:5) CHAR,
dummy FILLER POSITION(6:6),
COL_THREE INTEGER EXTERNAL TERMINATED BY "^",
COL_FOUR CHAR TERMINATED BY "^",
COL_FIVE CHAR TERMINATED BY "^",
COL_SIX CHAR TERMINATED BY "^"

The problem comes from your third field:

COL_THREE INTEGER EXTERNAL TERMINATED BY "^"

This field starts at position 6, which unfortunately contains a ^ so this field will be filled with a NULL value, pushing all following fields into the wrong columns.

You could use a filler to ignore the ^ character at position 6:

COL_ONE POSITION(1:3) INTEGER EXTERNAL,
COL_TWO POSITION(4:5) CHAR,
dummy FILLER POSITION(6:6),
COL_THREE INTEGER EXTERNAL TERMINATED BY "^",
COL_FOUR CHAR TERMINATED BY "^",
COL_FIVE CHAR TERMINATED BY "^",
COL_SIX CHAR TERMINATED BY "^"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文