通过sqlldr加载时如何忽略数据文件中可变数量的额外列字段

问题描述 投票:0回答:1

我有10个管道分隔数据的数据文件。数据文件可能少于10个字段或超过10个字段。在这种情况下,我应该如何编写控制文件?我的表只需要10个字段。如果字段较少,则应将其填充为null,如果字段更多,则应将其忽略。

oracle sql-loader
1个回答
1
投票

我想说的是您要寻找的是TRAILING NULLCOLS

顺便说一下,由于输入文件中字段的数量不同,您如何加载不同的数据类型?我以为它们都是VARCHAR2

这是一个示例(我只使用4列;不想输入那么多)。

表说明:

SQL> desc test
 Name                                      Null?    Type
 ----------------------------------------- -------- ----------------------------
 COL1                                               VARCHAR2(10)
 COL2                                               VARCHAR2(10)
 COL3                                               VARCHAR2(10)
 COL4                                               VARCHAR2(10)

控制文件:

load data 
infile *
replace
into table test
fields terminated by "|" 
trailing nullcols
(
col1,
col2,
col3,
col4
)

begindata
123|Little|foot|four
456|Access||
789|two|three|four|five|six|seven
111|

正在加载会话及其结果:

SQL> $sqlldr scott/tiger@kc11g control=test31.ctl log=test31.log

SQL*Loader: Release 11.2.0.1.0 - Production on Uto Lis 22 08:02:23 2019

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;

COL1       COL2       COL3       COL4
---------- ---------- ---------- ----------
123        Little     foot       four
456        Access
789        two        three      four
111

SQL>
© www.soinside.com 2019 - 2024. All rights reserved.