Search notes:

Oracle: SQL Loader example: fixed-width records

This example shows how to insert records from a source file with fixed-width columnar data.
The first filled column is filled with the current sysdate.

Destination table

Create the table that is to be filled:
create table tq84_sql_loader_1 (
   load_time            date,
   num                  number(7,2),
   txt_1                varchar2(7),
   txt_2                varchar2(10)
);
Github repository Oracle-Patterns, path: /SQLLoader/fixed-width/create_table.sql

Control file

The control file.
Note that the positions 11 through 20 are loaded into field_1 and positions 1 through 10 into field_2 (the column and input data order is different).
The field load_time is filled with the current time (sysdate) of the load.
options (
   errors = 0
)
load data
infile
   'load_1.dat'
insert
-- preserve blanks
--
--    Note, uncommenting 'preserve blanks' will
--    preserve blanks on an input string's right side, but
--    not on an input string's left side.
--    Null/empty numbers won't be loaded with
--    preserve blanks, though!
--
   into table tq84_sql_loader_1
(
   load_time    sysdate,
   num          position( 1: 8),
   txt_1        position(10:16), -- Note the gap (column 9)
   txt_2        position(18:27)
)
Github repository Oracle-Patterns, path: /SQLLoader/fixed-width/load_1.ctl

The dat file

The input-file's first column is an unaligned-number:
12345.67 one two abcdefghij
  42.42   three  ABC EF HIJ
 -9         four     xx    
           n/a   yyy yy    
  7.777              !     
Github repository Oracle-Patterns, path: /SQLLoader/fixed-width/load_1.dat

Load the data

$ sqlldr control=load_1.ctl userid=rene/password@ora.server.xy

See also

Other SQL Loader examples
SQL*Loader

Index