Skipping data fields while loading delimited data using SQLLDR

Vinod Yadav picture Vinod Yadav · Apr 17, 2015 · Viewed 46.5k times · Source

Consider below scenario:

Table T1 (f1, f2, f3);

Data files:

a|b|c|d
w|x|y|z

I want to load this data skipping the second field as follow:

f1    f2    f3 
---   ---   ---
a     d     c
w     z     y

Would really appreciate your help or any pointer in constructing the control file to achieve this.

Answer

Gary_W picture Gary_W · Apr 17, 2015

Define the column you want to skip as FILLER. Keep in mind the order of the columns in the control file is typically the order they are in the datafile. If the name matches a column in the table, that's where it will go.

...
(
  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
)

In other words, the order of the columns in the control file matches the order they are in the data file, not their order in the table. That is matched by name, not order.

EDIT - I added some comments for explanation, but I believe they can't be in that position in the actual file. See below for a full example:

Create table:

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

The control file, 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

Run it:

C:\temp>sqlldr userid=login/password@database 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

Select from the table:

enter image description here

Hopefully this helps.