我正在尝试使用以下记录加载示例数据文件:
12312^123456^0015GRAJ1M7J0002^SOME GIBBERISH ^123
我需要将这5个字段与6个数据库列相关联,其中第一个记录分为2:
'12312' -> '123' and '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
任何帮助都将受到高度赞赏。
答案 0 :(得分:3)
好的,问题通过反复试验解决了:
COL_ONE POSITION(1:3) INTEGER EXTERNAL,
COL_TWO CHAR TERMINATED BY "^",
.....
答案 1 :(得分:2)
问题来自你的第三个领域:
COL_THREE INTEGER EXTERNAL TERMINATED BY "^"
此字段从位置6开始,不幸的是,该字段包含^
,因此该字段将填充NULL值,将所有后续字段推入错误的列。
您可以使用filler忽略位置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 "^"