Skip to main content
Zezas

SQL* Loader - Copying data from/to Oracle DB

Today I needed to migrate data between two Databases, using sqlldr and spring-batch, here's some toughts on it:

Exporting data

Using a select query such as:

SELECT NVL(RPAD(DUMMY, 8,' '), RPAD(' ',8,' '))
FROM DUAL;

Gets us the data we need with a fixed width (using left-pad for numeric values and right-pad for everything else), the output is then written into a file.

Pros:

Cons:

Observations:

SELECT NVL(RPAD(
    REPLACE(DUMMY,CHR(10)||CHR(13),'{0}'), 8,' '),
    RPAD(' ',8,' '))
FROM DUAL;

Importing data

Using a Control file such as:

OPTIONS (BINDSIZE=512000, ROWS=10000)
LOAD DATA
CHARACTERSET WE8ISO8859P1
infile *
append
INTO TABLE MYSCHEMA.MYTABLE
(
    "ID"      POSITION (1:8),
    "FOO"     POSITION (9:108)
)

Using DIRECT path load is proven to be much faster but this way we can garantee constraint health as the job is performing inserts instead of populating Oracle tables with the data in the files.

The stack

I'm using a simple tasklet to perform generic extract/ loading of data. I might write another post with the details of our implementation.