2015-04-17 89 views

回答

8

定義您想跳過的列爲FILLER。請記住,控制文件中列的順序通常是它們在數據文件中的順序。如果該名稱與表格中的列匹配,那就是它將去的地方。

... 
(
    f1 CHAR, -- 1st field in the file, goes to column named f1 in the table 
    X FILLER, -- 2nd field in the file, ignored 
    f3 CHAR, -- 3rd field in the file, goes to column named f3 in the table 
    f2 CHAR -- 4th field in the file, goes to column named f2 in the table 
) 

換句話說,在控制文件中的列順序相匹配,他們是在數據文件中的順序,而不是它們在表中的順序。這是匹配的名稱,而不是秩序。

編輯 - 我添加了一些評論的解釋,但我相信他們不能在實際文件中的位置。對於一個完整的例子請看下圖:

創建表:

CREATE TABLE T1 
(
    F1 VARCHAR2(50 BYTE), 
    F2 VARCHAR2(50 BYTE), 
    F3 VARCHAR2(50 BYTE) 
); 

控制文件,example.ctl:

load data 
infile * 
truncate 
into table t1 
fields terminated by '|' trailing nullcols 
(
f1 CHAR, 
x FILLER, 
f3 CHAR, 
f2 CHAR 
) 
BEGINDATA 
a|b|c|d 
w|x|y|z 

運行:

C:\temp>sqlldr userid=login/[email protected] control=example.ctl 
SQL*Loader: Release 11.2.0.1.0 - Production on Wed Apr 22 11:25:49 2015 
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved. 
Commit point reached - logical record count 2 

從表中選擇:

enter image description here

希望這有助於。

+0

非常感謝你的這種做法。考慮到已經有大約35GB數據的表格的大小,我想到的這個特定方法是想避免的。而且,這不是一次性的過程,因此不確定這是否是一種好方法。 –

+0

您能否在此建議任何替代方法? –

+0

我不相信有人需要。這就是你如何跳過一個字段並創建一個可重用的控制文件。除非你想編寫某種程序去除你在加載之前不需要的字段,但是你仍然需要一個控制文件。也許我不明白爲什麼這種方法是一個問題? –