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