Sunteți pe pagina 1din 4

SQL*Loader

SQL*Loader is an Oracle-supplied utility that allows you to load data from a flat file
into one or more database tables. It has a powerful data parsing engine that
supports data present in any format in the data files. It can load data from multiple
datafiles during the same load session as well as can load data into multiple tables
during the same load session. SQL*Loader can manipulate the data before loading
it, using SQL functions.

Control File:
The control file is a text file written in a language that SQL*Loader understands. The
control file tells SQL*Loader where to find the data, how to parse and interpret the
data, where to insert the data, and more.

Bad File & Discard File:


Records read from the input file might not be inserted into the database. Such
records are placed in either a bad file or a discard file.
The bad file contains records that were rejected, either by SQL*Loader or by the
Oracle database. If you do not specify a bad file and there are rejected records, then
SQL*Loader automatically creates one. It will have the same name as the data file,
with a.bad extension.
Datafile records are rejected by SQL*Loader when the input format is invalid.
The row may be invalid because

a key is not unique


a required field is null
the field contains invalid data for the Oracle datatype

As SQL*Loader executes, it may create a file called the discard file. The discard file
contains records that were filtered out of the load because they did not match any
record-selection criteria specified in the control file. The discard file therefore
contains records that were not inserted into any table in the database.

Log File:
When SQL*Loader begins execution, it creates a log file. If it cannot create a log file,
execution terminates. The log file contains a detailed summary of the load,
including a description of any errors that occurred during the load.

SQL*Loaders Capabilities:

SQL*Loader can read from multiple input files in a single load session.

SQL*Loader can handle files with fixed-length records, variable-length records, and
stream-oriented data.

SQL*Loader supports a number of different datatypes, including text, numeric, zoned


decimal, packed decimal, and various machine-specific binary types.

Not only can SQL*Loader read from multiple input files, but it can load that data into
several different database tables, all in the same load session.

SQL*Loader allows you to use Oracles built-in SQL functions to manipulate the data
being read from the input file.

SQL*Loader includes functionality for dealing with whitespace, delimiters, and null data.

In addition to standard relational tables, SQL*Loader can load data into object tables,
varying arrays (VARRAYs), and nested tables.

SQL*Loader can load data into large object (LOB) columns.

SQL*Loader can handle character set translation between the input data file and the
database.

Application specific example:


In ABWS (Advanced Buried Wire System ) we receive flat file from business contact
on monthly basis and we load the data into ABWS DB table using sql loader and do
further processing on it. Below is control script (mw_tt_data_bo_ctl.ctl):
load data
infile 'tt_from_bo.txt'
append into table abcs.mw_tt_from_bo
FIELDS TERMINATED BY "~"
(date_created SYSDATE,
state_cd char,
dispatch_start_dt date 'MM/DD/YYYY',
dispatch_start_time char,
close_dt date 'MM/DD/YYYY',
close_time char,
trouble_tkt char,
billing_tel char,
circuit_id char,

trouble_reported char "SUBSTR(:trouble_reported,1,120)",


trouble_summary char "SUBSTR(:trouble_summary,1,60)",
disp_code_full char,
cause_code_full char,
orig_mpc_code CONSTANT '',
site_cd CONSTANT ''
)
Here tt_from_bo.txt is data file, sample data file attached below:
BSW_051214.txt

abcs.mw_tt_from_bo is target table, ~ is field delimiter.


Command to invoke sql loader:
Sqlldr user/pass@db_instance control=<>control file
Example: sqlldr abcs/XXX@p1aca1d2.db.att.com control=mw_tt_data_bo_ctl.ctl

S-ar putea să vă placă și