SQL Loader is a utility that allows you to load data of different format into Oracle. These formats
include delimited text file, csv file, etc... There are two important parts to running SQL Loader:
1. the SQL Loader command line
2. the control file
1. SQL Loader command line
On UNIX:
sqlldr CONTROL=/db01/DBSTAR/conversion/ctl/sample.ctl, LOG=/db01/DBSTAR/conversion/log/sample.log,USERID=userid/pwd, direct=true, errors=10000
date
On NT:
sqlldr80 CONTROL=m:\db01\DBSTAR\conversion\ctl\sample.ctl LOG=\db01\DBSTAR\conversion\log\sample.log USERID=userid/pwd direct=true errors=10000
You can specify the data file in the command line. The parameter is called DATA.
For example:
sqlldr80 CONTROL=m:\db01\DBSTAR\conversion\ctl\sample.ctl DATA=m:\db01\DBSTAR\conversion\sample.txt LOG=\db01\DBSTAR\conversion\log\sample.log USERID=userid/pwd direct=true errors=10000
Note specifying the data file in the control file, the parameter is INFILE sample.txt however
in the sql loader command line, the parameter in DATA sample.txt
The following is a list of all the parameters that may be used in the command line:
USERID - Oracle username/password
CONTROL - Control file name
LOG - Log file name
BAD - Bad file name
DATA - Data file name
DISCARD - Discard file name
DISCARDMAX - Number of discards to allow (Default all)
SKIP - Number of logical records to skip (Default 0)
LOAD - Number of logical records to load (Default all)
ERRORS - Number of errors to allow (Default 50)
ROWS - Number of rows in conventional path bind array or between direct path data saves
(Default: Conventional Path 64, Direct path all)
BINDSIZE - Size of conventional path bind array in bytes (System-dependent default)
SILENT - Suppress messages during run (header, feedback, errors, discards, partitions, all)
DIRECT - Use direct path (Default FALSE)
PARFILE - Parameter file: name of file that contains parameter specifications
PARALLEL - Perform parallel load (Default FALSE)
FILE - File to allocate extents from
2. The control file
specify -- for comment line
OPTIONS keyword allows you to specify runtime arguments in the control file rather than
in the command line. It always precede the LOAD DATA keyword
Ex: OPTIONS (DIRECT=TRUE ERRORS=10000 SILENT=(ERRORS, FEEDBACK))
Other parameters that are specified in the control file are:
RECOVERABLE/UNRECOVERABLE - Loaded data is logged in the redo log if RECOVERABLE.
RECOVERABLE is default for direct path loads. All conventional loads are recoverable.
UNRECOVERABLE can only be specified for DIRECT path and is used to improve performance
LOAD DATA - command to start loading the data
INFILE - File to load data from multiple datafiles in one run of SQL*Loader
Ex: INFILE mydat1.dat BADFILE mydat1.bad DISCARDFILE mydat1.dis
INFILE mydat2.dat
BADFILE - File for SQL Loader to place records that were rejected because of formatting errors
or because they caused Oracle errors.
DISCARDFILE - File for SQL Loader to place records that do not meet any of the loading criteria
(does not meet the WHEN criteria)
INSERT/APPEND/REPLACE/TRUNCATE - command to specify how to laod the data
The following are examples of a control file:
----------
Example 1: Loading fixed length file
In the database, make sure that the table you are loading the data in exist:
Sample table: create table sample
(sample_col1 char(1),
sample_col3 char(2));
Control file, sample.ctl:
OPTIONS (DIRECT=TRUE ERRORS=10000)
UNRECOVERABLE
LOAD DATA
INFILE sample.txt
--
TRUNCATE
INTO TABLE sample
--
(sample_col1 POSITION(01:08) CHAR,
sample_col2 POSITION(11:16) DATE "YYMMDD" NULLIF collection_date=BLANKS,
sample_col3 POSITION(17:25) DECIMAL EXTERNAL,
sample_col4 POSITION(33:67) CHAR)
SQL Loader command line:
sqlldr userid=userid/pwd@dbalias control=sample.ctl, log=sample.log
----------
Example 2: Loading data from a comma delimited file
In the database, make sure that the table you are loading the data in exist:
Sample table:
create table sample
(stats_type varchar2(100),
STATS_DATE date ,
STATS_NAME varchar2(100),
VALUE1 number ,
VALUE2 number ,
VALUE3 number ,
VALUE4 number ,
VALUE5 number ,
VALUE6));
Control file, comma.ctl:
load data
infile comma.dat
truncate
into table comma_table
FIELDS TERMINATED BY ','
trailing nullcols
(stats_type,
STATS_DATE ,
STATS_NAME ,
VALUE1 ,
VALUE2 ,
VALUE3 ,
VALUE4 ,
VALUE5 ,
VALUE6
)
SQL Loader command line:
sqlldr control=comma.ctl, bad=comma.bad, log=comma.log, userid=userid/pwd@db
For more examples and further explanation, refer to the oracle documentation under utilities.
|