Академический Документы
Профессиональный Документы
Культура Документы
SQL*Loader loads data from external files into tables of an Oracle database. It has a powerful data parsing engine that puts little limitation on the format of the data in the datafile. You can use SQL*Loader to do the following: Load data across a network if our data files are on a different s stem than the database. Load data from multiple datafiles during the same load session. Load data into multiple tables during the same load session. Specif the character set of the data. Selecti!el load data " ou can load records based on the records# !alues$. %anipulate the data before loading it& using SQL functions. 'enerate uni(ue se(uential ke !alues in specified columns. )se the operating s stem#s file s stem to access the datafiles. Load data from disk& tape& or named pipe. 'enerate sophisticated error reports& which greatl aid troubleshooting. Load arbitraril complex ob*ect+relational data. )se secondar datafiles for loading LO,s and collections. t pical SQL*Loader session takes as input a control file& which controls the beha!ior of SQL*Loader& and one or more datafiles. -he output of SQL*Loader is an Oracle database "where the data is loaded$& a log file& a bad file& and potentiall & a discard file. .n example of the flow of a SQL*Loader session is shown in /igure 0+1.
SQL*Loader Parameters
SQL*Loader is in!oked when ou specif the sqlldr command and& optionall & parameters that establish session characteristics. In situations where ou alwa s use the same parameters for which the !alues seldom change& it can be more efficient to specif parameters using the following methods& rather than on the command line: 2arameters can be grouped together in a parameter file. You could then specif the name of the parameter file on the command line using the PARFILE parameter. 3ertain parameters can also be specified within the SQL*Loader control file b using the OPTIONS clause. 2arameters specified on the command line o!erride an parameter !alues specified in a parameter file or OPTIONS clause.
/or securit reasons& ou should not include our USERID password in a parameter file. SQL*Loader will prompt ou for the password after ou specif the parameter file at the command line& for example:
sqlldr"PARFILE=daily_report.par Pass#ord$"pass#ord
Some control file s ntax considerations to keep in mind are: -he s ntax is free+format "statements can extend o!er multiple lines$. It is case insensiti!e7 howe!er& strings enclosed in single or double (uotation marks are taken literall & including case. In control file s ntax& comments extend from the two h phens "++$ that mark the beginning of the comment to the end of the line. -he optional third section of the control file is interpreted as data rather than as control file s ntax7 conse(uentl & comments in this section are not supported. -he ke words CONSTANT and &ONE ha!e special meaning to SQL*Loader and are therefore reser!ed. -o a!oid potential conflicts& Oracle recommends that ou do not use either CONSTANT or &ONE as a name for an tables or columns.
Specifying atafiles
-o specif a datafile that contains the data to be loaded& use the INFILE ke word& followed b the filename and optional file processing options string. You can specif multiple files b using multiple INFILE ke words.
/or (ydat..dat5 both a bad file and discard file are explicitl specified. -herefore both files are created& as needed. /or (ydat/.dat5 neither a bad file nor a discard file is specified. -herefore& onl the bad file is created& as needed. If created& the bad file has the default filename and extension (ydat/.-ad. -he discard file is not created& e!en if rows are discarded. /or (ydat0.dat5 the default bad file is created& if needed. . discard file with the specified name "(ydat0.dis$ is created& as needed. /or (ydat1.dat5 the default bad file is created& if needed. ,ecause the DISCARD2A3 option is used& SQL*Loader assumes that a discard file is re(uired and creates it with the default name (ydat1.dsc.
:eep the following points in mind when using the %E INDATA statement: If ou omit the %E INDATA statement but include data in the control file& SQL*Loader tries to interpret our data as control information and issues an error message. If our data is in a separate file& do not use the %E INDATA statement. 4o not use spaces or other characters on the same line as the %E INDATA statement& or the line containing %E INDATA will be interpreted as the first line of data. 4o not put comments after %E INDATA5 or the will also be interpreted as data.
string "os_)ile_proc_cla,se$ in the control file to specif file format and buffering. /or example& suppose that our operating s stem has the following option+string s ntax:
4escription of the illustration recsi5e;spec.gif In this s ntax& RECSI&E is the si5e of a fixed+length record& and %UFFERS is the number of buffers to use for as nchronous I<O. -o declare a file named (ydata.dat as a file that contains =>+b te records and instruct SQL*Loader to use = I<O buffers& ou would use the following control file entr :
INFILE"*(ydata.dat*"6RECSI&E"74"%UFFERS"76"
-o specif a bad file with filename -ad444. and file extension or file t pe of .re85 enter either of the following lines:
%ADFILE"-ad444..re8 %ADFILE"*+RE9ECT_DIR+-ad444..re8*"
the DISCARDFILE clause specifies that a discard filename follows. -he )ile<a(e parameter specifies a !alid filename specification for our platform. .n spaces or punctuation marks in the filename must be enclosed in single (uotation marks. -he default filename is the name of the datafile& and the default file extension or file t pe is .dsc. . discard filename specified on the command line o!errides one specified in the control file. If a discard file with that name alread exists& it is either o!erwritten or a new !ersion is created& depending on our operating s stem
. nonpartitioned table
Case 1 @ A C E 0 F
= G 1> 11
-his prepares and populates tables for the case stud and then returns ou to the s stem prompt. A. .t the s stem prompt& in!oke SQL*Loader and run the case stud & as follows:
sqlldr"USERID=scott"CONTROL=,lcase..ctl"LO =,lcase..lo!
Substitute the appropriate control file name and log file name for the CONTROL and LO parameters and press 6nter. 8hen ou are prompted for a password& t pe ti!er and then press 6nter. ,e sure to read the control file for an notes that are specific to the particular case stud ou are executing. /or example& case stud 0 re(uires that ou add DIRECT=TRUE to the SQL*Loader command line.