Beruflich Dokumente
Kultur Dokumente
This chapter describes the SQL*Loader control file. The following topics are included:
Control File Contents
Specifying Command-Line arameters in the Control File
Specifying Filenames and !b"ect #ames
Specifying $atafiles
%dentifying $ata in the Control File with &'(%#$)T)
Specifying $atafile Format and &uffering
Specifying the &ad File
Specifying the $iscard File
*andling $ifferent Character 'ncoding Schemes
%nterrupted Loads
)ssembling Logical +ecords from hysical +ecords
Loading Logical +ecords into Tables
%nde, !ptions
&enefits of -sing .ultiple %#T! T)&L' Clauses
&ind )rrays and Con/entional ath Loads
Control File Contents
The SQL*Loader control file is a te,t file that contains data definition language 0$$L1
instructions. $$L is used to control the following aspects of a SQL*Loader session:
2here SQL*Loader will find the data to load
*ow SQL*Loader e,pects that data to be formatted
*ow SQL*Loader will be configured 0memory management3 re"ecting records3
interrupted load handling3 and so on1 as it loads the data
*ow SQL*Loader will manipulate the data being loaded
See )ppendi, ) for synta, diagrams of the SQL*Loader $$L.
To create the SQL*Loader control file3 use a te,t editor such as /i or ,emacs.create.
%n general3 the control file has three main sections3 in the following order:
Session-wide information
Table and field-list information
%nput data 0optional section1
',ample 4-5 shows a sample control file.
Example 5-1 Sample Control File
1 -- This is a sample control file
2 LOAD DATA
3 INFILE 'sample.dat'
4 BADFILE 'sample.bad'
5 DISA!DFILE 'sample.dsc'
6 A""END
7 INTO TABLE emp
8 #$EN %&'( ) '.'
9 T!AILIN* N+LLOLS
10 %hiredate S,SDATE-
deptno "OSITION%./0( INTE*E! E1TE!NAL%0(
N+LLIF deptno)BLAN2S-
3ob "OSITION%'/.4( $A! TE!5INATED B, #$ITES"AE
N+LLIF 3ob)BLAN2S 6+""E!%/3ob(6-
m7r "OSITION%08/9.( INTE*E! E1TE!NAL
TE!5INATED B, #$ITES"AE- N+LLIF m7r)BLAN2S-
ename "OSITION%94/4.( $A!
TE!5INATED B, #$ITES"AE 6+""E!%/ename(6-
empno "OSITION%4&( INTE*E! E1TE!NAL
TE!5INATED B, #$ITES"AE-
sal "OSITION%&.( $A! TE!5INATED B, #$ITES"AE
6TO:N+5BE!%/sal-';<<-<<<.<<'(6-
comm INTE*E! E1TE!NAL ENLOSED B, '%' AND '='
6/comm > .??6
(
%n this sample control file3 the numbers that appear to the left would not appear in a real
control file. They are 6eyed in this sample to the e,planatory notes in the following list:
5. This is how comments are entered in a control file. See Comments in the Control
File.
5. The LOAD DATA statement tells SQL*Loader that this is the beginning of a new
data load. See )ppendi, ) for synta, information.
5. The INFILE clause specifies the name of a datafile containing data that you want
to load. See Specifying $atafiles.
5. The BADFILE parameter specifies the name of a file into which re"ected records
are placed. See Specifying the &ad File.
5. The DISA!DFILE parameter specifies the name of a file into which discarded
records are placed. See Specifying the $iscard File.
5. The A""END parameter is one of the options you can use when loading data into a
table that is not empty. See Loading $ata into #onempty Tables.
To load data into a table that is empty3 you would use the INSE!T parameter. See
Loading $ata into 'mpty Tables.
5. The INTO TABLE clause allows you to identify tables3 fields3 and datatypes. %t
defines the relationship between records in the datafile and tables in the database.
See Specifying Table #ames.
5. The #$EN clause specifies one or more field conditions. SQL*Loader decides
whether or not to load the data based on these field conditions. See Loading
+ecords &ased on a Condition.
5. The T!AILIN* N+LLOLS clause tells SQL*Loader to treat any relati/ely
positioned columns that are not present in the record as null columns. See
*andling Short +ecords with .issing $ata.
5. The remainder of the control file contains the field list3 which pro/ides
information about column formats in the table being loaded. See Chapter 7 for
information about that section of the control file.
Comments in the Control File
Comments can appear anywhere in the command section of the file3 but they should not
appear within the data. recede any comment with two hyphens3 for e,ample:
--This is a comment
)ll te,t to the right of the double hyphen is ignored3 until the end of the line. )n e,ample
of comments in a control file is shown in Case Study 8: Loading a $elimited3 Free-
Format File.
Specifying Command-Line Parameters in the
Control File
The O"TIONS clause is useful when you typically in/o6e a control file with the same set
of options. The O"TIONS clause precedes the LOAD DATA statement.
OPTIOS Cla!se
The O"TIONS clause allows you to specify runtime parameters in the control file3 rather
than on the command line. The following parameters can be specified using the O"TIONS
clause. These parameters are described in greater detail in Chapter 9.
BINDSI@E ) n
OL+5NA!!A,!O#S ) n
DI!ET ) AT!+E B FALSEC
E!!O!S ) n
LOAD ) n
5+LTIT$!EADIN* ) AT!+E B FALSEC
"A!ALLEL ) AT!+E B FALSEC
!EADSI@E ) n
!ES+5ABLE ) AT!+E B FALSEC
!ES+5ABLE:NA5E ) 'teDt strin7'
!ES+5ABLE:TI5EO+T ) n
!O#S ) n
SILENT ) A$EADE!S B FEEDBA2 B E!!O!S B DISA!DS B "A!TITIONS B ALLC
S2I" ) n
S2I":INDE1:5AINTENANE ) AT!+E B FALSEC
S2I":+N+SABLE:INDE1ES ) AT!+E B FALSEC
ST!EA5SI@E ) n
For e,ample:
O"TIONS %BINDSI@E).?????- SILENT)%E!!O!S- FEEDBA2( (
ote"
:alues specified on the command line o/erride /alues specified in the
O"TIONS clause in the control file.
Specifying Filenames and O#$ect ames
%n general3 SQL*Loader follows the SQL standard for specifying ob"ect names 0for
e,ample3 table and column names1. The information in this section discusses the
following topics:
Filenames That Conflict with SQL and SQL*Loader +eser/ed 2ords
Specifying SQL Strings
!perating System Considerations
Filenames That Conflict %ith SQL and SQL*Loader Reser&ed
'ords
SQL and SQL*Loader reser/ed words must be specified within double ;uotation mar6s.
The only SQL*Loader reser/ed word is ONSTANT.
<ou must use double ;uotation mar6s if the ob"ect name contains special characters other
than those recogni=ed by SQL 0>3 ?3 @13 or if the name is case sensiti/e.
See (lso"
Oracle9i SQL Reference
Specifying SQL Strings
<ou must specify SQL strings within double ;uotation mar6s. The SQL string applies
SQL operators to data fields.
See (lso"
)pplying SQL !perators to Fields
Operating System Considerations
The following sections discuss situations in which your course of action may depend on
the operating system you are using.
Specifying a Complete Path
%f you encounter problems when trying to specify a complete path name3 it may be due to
an operating system-specific incompatibility caused by special characters in the
specification. %n many cases3 specifying the path name within single ;uotation mar6s
pre/ents errors.
%f not3 please see your !racle operating system-specific documentation for possible
solutions.
)ac*slash +scape Character
%n $$L synta,3 you can place a double ;uotation mar6 inside a string delimited by
double ;uotation mar6s by preceding it with the escape character3 ABA 0if the escape
character is allowed on your operating system1. The same rule applies when single
;uotation mar6s are re;uired in a string delimited by single ;uotation mar6s.
For e,ample3 homedirBdataAnormBmydata contains a double ;uotation mar6. receding
the double ;uotation mar6 with a bac6slash indicates that the double ;uotation mar6 is to
be ta6en literally:
INFILE 'homedirEdataE6normEmFdata'
<ou can also put the escape character itself into a string by entering it twice:
For e,ample:
6so'E6far6 or 'soE'6far' is parsed as so'6far
6'soEEfar'6 or 'E'soEEfarE'' is parsed as 'soEfar'
6soEEEEfar6 or 'soEEEEfar' is parsed as soEEfar
ote"
) double ;uotation mar6 in the initial position cannot be preceded by
an escape character. Therefore3 you should a/oid creating strings with
an initial ;uotation mar6.
onporta#le Strings
There are two 6inds of character strings in a SQL*Loader control file that are not
portable between operating systems: filename and file processing option strings. 2hen
you con/ert to a different operating system3 you will probably need to modify these
strings. )ll other strings in a SQL*Loader control file should be portable between
operating systems.
+scaping the )ac*slash
%f your operating system uses the bac6slash character to separate directories in a path
name3 and if the /ersion of the !racle database ser/er running on your operating system
implements the bac6slash escape character for filenames and other nonportable strings3
then you must specify double bac6slashes in your path names and use single ;uotation
mar6s.
See your !racle operating system-specific documentation for information about which
escape characters are re;uired or allowed.
+scape Character Is Sometimes ,isallo%ed
The /ersion of the !racle database ser/er running on your operating system may not
implement the escape character for nonportable strings. 2hen the escape character is
disallowed3 a bac6slash is treated as a normal character3 rather than as an escape character
0although it is still usable in all other strings1. Then path names such as the following can
be specified normally:
INFILE 'topdirEmFdirEmFfile'
$ouble bac6slashes are not needed.
&ecause the bac6slash is not recogni=ed as an escape character3 strings within single
;uotation mar6s cannot be embedded inside another string delimited by single ;uotation
mar6s. This rule also holds for double ;uotation mar6s. ) string within double ;uotation
mar6s cannot be embedded inside another string delimited by double ;uotation mar6s.
Specifying ,atafiles
To specify a datafile that contains the data to be loaded3 use the INFILE clause3 followed
by the filename and optional file processing options string. <ou can specify multiple files
by using multiple INFILE clauses.
ote"
<ou can also specify the datafile from the command line3 using the
DATA parameter described in Command-Line arameters. ) filename
specified on the command line o/errides the first INFILE clause in the
control file.
%f no filename is specified3 the filename defaults to the control filename with an e,tension
or file type of .dat.
%f the control file itself contains the data to be loaded3 specify an asteris6 0*1. This
specification is described in %dentifying $ata in the Control File with &'(%#$)T) .
ote"
The information in this section applies only to primary datafiles. %t does
not apply to L!&F%L's or S$Fs.
For information about L!&F%L'S3 see Loading L!& $ata from
L!&F%L's.
For information about S$Fs3 see Secondary $atafiles 0S$Fs1.
The synta, for the INFILE clause is as follows:
Te,t description of the illustration infile.gif
Te,t description of the illustration infileC.gif
Table 4-5 describes the parameters for the INFILE clause.
Table 5-1 Parameters for the INFILE Clause
Parameter ,escription
INFILE or INDDN
Specifies that a datafile specification follows.
#ote that INDDN has been retained for situations in which
compatibility with $&C is re;uired.
input_filename
#ame of the file containing the data.
)ny spaces or punctuation mar6s in the filename must be
enclosed in single ;uotation mar6s. See Specifying Filenames
and !b"ect #ames.
* %f your data is in the control file itself3 use an asteris6 instead of
the filename. %f you ha/e data in the control file as well as
datafiles3 you must specify the asteris6 first in order for the data
to be read.
os_file_proc_clause
This is the file-processing options string. %t specifies the datafile
format. %t also optimi=es datafile reads. The synta, used for this
string is specific to your operating system. See Specifying
$atafile Format and &uffering.
+-amples of IFIL+ Synta-
The following list shows different ways you can specify INFILE synta,:
$ata contained in the control file itself:
INFILE >
ote"
Filenames that include spaces or punctuation mar6s must be enclosed
in single ;uotation mar6s. For more details on filename specification3
see Specifying Filenames and !b"ect #ames.
Specifying .!ltiple ,atafiles
To load data from multiple datafiles in one SQL*Loader run3 use an INFILE statement for
each datafile. $atafiles need not ha/e the same file processing options3 although the
layout of the records must be identical. For e,ample3 two files could be specified with
completely different file processing options strings3 and a third could consist of data in
the control file.
<ou can also specify a separate discard file and bad file for each datafile. %n such a case3
the separate bad files and discard files must be declared immediately after each datafile
name. For e,ample3 the following e,cerpt from a control file specifies four datafiles with
separate bad and discard files:
INFILE mFdat..dat BADFILE mFdat..bad DISA!DFILE mFdat..dis
INFILE mFdat0.dat
INFILE mFdat9.dat DISA!DFILE mFdat9.dis
INFILE mFdat4.dat DISA!D5A1 .? ?
For mFdat..dat- both a bad file and discard file are e,plicitly specified.
Therefore both files are created3 as needed.
For mFdat0.dat- neither a bad file nor a discard file is specified. Therefore3 only
the bad file is created3 as needed. %f created3 the bad file has the default filename
and e,tension mFdat0.bad. The discard file is not created3 e/en if rows are
discarded.
For mFdat9.dat- the default bad file is created3 if needed. ) discard file with the
specified name 0mFdat9.dis1 is created3 as needed.
For mFdat4.dat- the default bad file is created3 if needed. &ecause the
DISA!D5A1 option is used3 SQL*Loader assumes that a discard file is re;uired
and creates it with the default name mFdat4.dsc.
Identifying ,ata in the Control File %ith
)+/I,(T(
%f the data is included in the control file itself3 then the INFILE clause is followed by an
asteris6 rather than a filename. The actual data is placed in the control file after the load
configuration specifications.
Specify the BE*INDATA parameter before the first data record. The synta, is:
BE*INDATA
data
Deep the following points in mind when using the BE*INDATA parameter:
%f you omit the BE*INDATA parameter but include data in the control file3
SQL*Loader tries to interpret your data as control information and issues an error
message. %f your data is in a separate file3 do not use the BE*INDATA parameter.
$o not use spaces or other characters on the same line as the BE*INDATA
parameter3 or the line containing BE*INDATA will be interpreted as the first line of
data.
$o not put comments after BE*INDATA- or they will also be interpreted as data.
See (lso"
Specifying $atafiles for an e,planation of using INFILE
Case Study 5: Loading :ariable-Length $ata
Specifying ,atafile Format and )!ffering
2hen configuring SQL*Loader3 you can specify an operating system-dependent file
processing options string 0os_file_proc_clause1 in the control file to specify file
format and buffering.
For e,ample3 suppose that your operating system has the following option-string synta,:
Te,t description of the illustration recsi=e.gif
%n this synta,3 !ESI@E is the si=e of a fi,ed-length record3 and B+FFE!S is the number of
buffers to use for asynchronous %E!.
To declare a file named mFdata.dat as a file that contains FG-byte records and instruct
SQL*Loader to use F %E! buffers3 you would use the following control file entry:
INFILE 'mFdata.dat' 6!ESI@E 8? B+FFE!S 86
For details on the synta, of the file processing options string3 see your !racle operating
system-specific documentation.
ote"
This e,ample uses the recommended con/ention of single ;uotation
mar6s for filenames and double ;uotation mar6s for e/erything else.
Specifying the )ad File
2hen SQL*Loader e,ecutes3 it can create a file called a bad file or re"ect file in which it
places records that were re"ected because of formatting errors or because they caused
!racle errors. %f you ha/e specified that a bad file is to be created3 the following applies:
%f one or more records are re"ected3 the bad file is created and the re"ected records
are logged.
%f no records are re"ected3 then the bad file is not created. 2hen this occurs3 you
must reinitiali=e the bad file for the ne,t run.
%f the bad file is created3 it o/erwrites any e,isting file with the same nameH
ensure that you do not o/erwrite a file you wish to retain.
ote"
!n some systems3 a new /ersion of the file is created if a file with the
same name already e,ists. See your !racle operating system-specific
documentation to find out if this is the case on your system.
To specify the name of the bad file3 use the BADFILE parameter 0or BADDN for $&C
compatibility13 followed by the bad file filename. %f you do not specify a name for the bad
file3 the name defaults to the name of the datafile with an e,tension or file type of .bad.
<ou can also specify the bad file from the command line with the BAD parameter
described in Command-Line arameters.
) filename specified on the command line is associated with the first INFILE or INDDN
clause in the control file3 o/erriding any bad file that may ha/e been specified as part of
that clause.
The bad file is created in the same record and file format as the datafile so that the data
can be reloaded after ma6ing corrections. For datafiles in stream record format3 the
record terminator that is found in the datafile is also used in the bad file.
The synta, for the bad file is as follows:
Te,t description of the illustration badfile.gif
The BADFILE or BADDN parameter specifies that a filename for the bad file follows. 0-se
BADDN when $&C compatibility is re;uired.1
The bad_filename parameter specifies a /alid filename specification for your platform.
)ny spaces or punctuation mar6s in the filename must be enclosed in single ;uotation
mar6s.
+-amples of Specifying a )ad File ame
To specify a bad file with filename foo and default file e,tension or file type of .bad-
enter:
BADFILE foo
To specify a bad file with filename bad???. and file e,tension or file type of .re3- enter
either of the following lines:
BADFILE bad???..re3
BADFILE 'G!EIET:DI!Gbad???..re3'
0o% )ad Files (re 0andled %ith LO)FIL+s and S,Fs
$ata from L!&F%L's and S$Fs is not written to a bad file when there are re"ected rows.
%f there is an error loading a L!&3 the row is not re"ected. +ather3 the LOB column is left
empty 0not null with a length of =ero 0G1 bytes1. *owe/er3 when the L!&F%L' is being
used to load an 15L column and there is an error loading this L!& data3 then the 15L
column is left as null.
Criteria for Re$ected Records
) record can be re"ected for the following reasons:
5. -pon insertion3 the record causes an !racle error 0such as in/alid data for a gi/en
datatype1.
5. The record is formatted incorrectly so that SQL*Loader cannot find field
boundaries.
5. The record /iolates a constraint or tries to ma6e a uni;ue inde, non-uni;ue.
%f the data can be e/aluated according to the #$EN clause criteria 0e/en with unbalanced
delimiters13 then it is either inserted or re"ected.
#either a con/entional path nor a direct path load will write a row to any table if it is
re"ected because of reason number C in the pre/ious list.
)dditionally3 a con/entional path load will not write a row to any tables if reason number
5 or 8 in the pre/ious list is /iolated for any one table. The row is re"ected for that table
and written to the re"ect file.
The log file indicates the !racle error for each re"ected record. Case Study 9: Loading
Combined hysical +ecords demonstrates re"ected records.
Specifying the ,iscard File
$uring SQL*Loader e,ecution3 it can create a discard file for records that do not meet
any of the loading criteria. The records contained in this file are called discarded records.
$iscarded records do not satisfy any of the #$EN clauses specified in the control file.
These records differ from re"ected records. Discarded records do not necessarily have
any bad data. #o insert is attempted on a discarded record.
) discard file is created according to the following rules:
<ou ha/e specified a discard filename and one or more records fail to satisfy all of
the #$EN clauses specified in the control file. 0%f the discard file is created3 it
o/erwrites any e,isting file with the same name3 so be sure that you do not
o/erwrite any files you wish to retain.1
%f no records are discarded3 then a discard file is not created.
To create a discard file from within a control file3 specify any of the following:
DISA!DFILE filename3 DISA!DDN filename 0$&C13 DISA!DS3 or DISA!D5A1.
To create a discard file from the command line3 specify either DISA!D or DISA!D5A1.
<ou can specify the discard file directly by specifying its name3 or indirectly by
specifying the ma,imum number of discards.
The discard file is created in the same record and file format as the datafile. For datafiles
in stream record format3 the same record terminator that is found in the datafile is also
used in the discard file.
Specifying the ,iscard File in the Control File
To specify the name of the file3 use the DISA!DFILE or DISA!DDN 0for $&C-
compatibility1 parameter3 followed by the filename.
Te,t description of the illustration discard.gif
The DISA!DFILE or DISA!DDN parameter specifies that a discard filename follows.
0-se DISA!DDN when $&C compatibility is re;uired.1
The discard_filename parameter specifies a /alid filename specification for your
platform. )ny spaces or punctuation mar6s in the filename must be enclosed in single
;uotation mar6s.
The default filename is the name of the datafile3 and the default file e,tension or file type
is .dsc. ) discard filename specified on the command line o/errides one specified in the
control file. %f a discard file with that name already e,ists3 it is either o/erwritten or a new
/ersion is created3 depending on your operating system.
Specifying the ,iscard File from the Command Line
See $%SC)+$ 0filename1 for information on how to specify a discard file from the
command line.
) filename specified on the command line o/errides any discard file that you may ha/e
specified in the control file.
+-amples of Specifying a ,iscard File ame
The following list shows different ways you can specify a name for the discard file from
within the control file:
To specify a discard file with filename circHlar and default file e,tension or file
type of .dsc:
DISA!DFILE circHlar
To specify a discard file named notappl with the file e,tension or file type
of .maF:
DISA!DFILE notappl.maF