/  10
 
SQL*LOADER
Defination:
 
1)
SQL*Loader loads data from external files into tables of an Oracle database.
2)
The control file is a text file written in a language that SQL*Loader understands
. 
3)
The SQL*Loader Control File 
The SQL*Loader control file is a repository that contains the DDL instructions thatyou have created to control where SQL*Loader will find the data to load, how SQL*Loader expects thatdata to be formatted, how SQL*Loader will be configured (memory management, rejecting records,interrupted load handling, and so on) as it loads the data, and how it will manipulate the data beingloaded. You create the SQL*Loader control file and its contents using a simple text editor such as vi or xemacs.
Description:
SQL*Loader takes as input a control file, which controls the behavior of SQL*Loader,and one or more datafiles. The output of SQL*Loader is an Oracle database (where the data is loaded), alog file, a bad file, and potentially, a discard file.You use SQL*Loader's data definition language (DDL) tocontrol how SQL*Loader performs a data load into your database. You can also use DDL to manipulate thedata you are loading.The control file describes the task that SQL*Loader is to carry out. 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.The controlfile has three sections
 
a) The first section contains session-wide information,for example:Global options such as bindsize, rows, records to skip, and so on INFILE clauses to specifywhere the input data is located Data character set specification
 
b)The second section consists of one or more "INTO TABLE" blocks. Each of these blocks containsinformation about the table into which the data is to be loaded, such as the table name and thecolumns of the table.
 
c)The third section is optional and, if present, contains input data.Note that the optional thirdsection of the control file is interpreted as data rather than as control file syntax;consequently,comments in this section are not supported.The other input to SQL*Loader, other than the control file, is the data.SQL*Loader's perspective,the data in the datafile is organized as records. A particular datafile can be in fixed record format,variable record format, or stream record format. Important: If data is specified inside the controlfile(that is, INFILE * was specified in the control file), then the data is interpreted in the streamrecordformat with the default record terminator.
Fixed Record Format:
When all records in a datafile are the same byte length, the file is infixed record format. Although this format is the least flexible, it does result in better performancethan variable or stream format. Fixed format is also simple to specify.
Loading Data in Fixed Record Format
 load datainfile 'example.dat' "fix 11"into table examplefields terminated by ',' optionally enclosed by '"'(col1 char(5),col2 char(7))
 
example.dat:001, cd, 0002,fghi,00003,lmn,1, "pqrs",0005,uvwx,
Variable Record Format:
When you specify that a datafile is in variable record format, SQL*Loader expects to find the length of each record in a character field at the beginning of each record in the datafile.This format provides some added flexibility over the fixed record format and a performance advantage over the stream record format.The example.dat datafile consists of three physical records. The first is specified to be 009 (that is, 9)bytes long, the second is 010 bytes long, and the third is 012 bytes long. This example also assumes asingle-byte character set for the datafile.
Loading Data in Variable Record Format
load datainfile 'example.dat' "var 3"into table examplefields terminated by ',' optionally enclosed by '"'(col1 char(5),col2 char(7))example.dat:009hello,cd,010world,im,012my,name is,
Stream Record Format (SRF)
Stream record format is the most flexible format. There is, however, someeffect on performance. In stream record format, records are not specified by size. Instead,SQL*Loader forms records by scanning for the record terminator.If no terminator_string is specified, it defaults to thenewline (end-of-line) character The datafile in the example consists of two records, both properly terminated by the '|\n' string(that is, X'7c0a').
Loading Data in Stream Record Format
load datainfile 'example.dat' "str X'7c0a'"into table examplefields terminated by ',' optionally enclosed by '"'(col1 char(5),col2 char(7))example.dat:hello,world,| james,bond,|
Logical Records
SQL*Loader organizes the input data into physical records, according to the specifiedrecord format. By default a physical record is a logical record, but for added flexibility, SQL*Loader canbe instructed to combine a number of physical records into a logical record. SQL*Loader can beinstructed to follow one of the following two logical record forming strategies:n Combine a fixednumber of physical records to form each logical record.n Combine physical records into logical recordswhile a certain condition is true.LOAD DATAINFILE 'ulcase4.dat'
1)
DISCARDFILE 'ulcase4.dsc'
2)
DISCARDMAX 999
 
3)
REPLACE
4)
CONTINUEIF THIS (1) = '*'INTO TABLE emp(empno POSITION(1:4) INTEGER EXTERNAL,ename POSITION(6:15) CHAR, job POSITION(17:25) CHAR,mgr POSITION(27:30) INTEGER EXTERNAL,sal POSITION(32:39) DECIMAL EXTERNAL,comm POSITION(41:48) DECIMAL EXTERNAL,deptno POSITION(50:51) INTEGER EXTERNAL,hiredate POSITION(52:60) INTEGER EXTERNAL)1)DISCARDFILE specifies a discard file named ULCASE4.DSC. 2)
 
DISCARDMAX specifies a maximum of 999 discards allowed before terminating the run (for all practical purposes, this allows all discards).3)REPLACE specifies that if there is data in the table being loaded, then SQL*Loader shoulddelete that data before loading new data.
 
4)CONTINUEIF THIS specifies that if an asterisk is found in column 1 of the current record, thenthe next physical record after that record should be appended to it to from the logical record.Note that column 1 in each physical record should then contain either an asterisk or a nondatavalue.The Oracle database server uses the datatype of the column to convert the data into its final,stored form. There are two conversion steps:
1.
SQL*Loader identifies a field in the datafile, interprets the data, and passes it tothe Oracle database server using a bind buffer.
 
2.
The Oracle database server accepts the data and stores it in the database.Note that the control file CHAR specification is not the same as the database CHARspecification. A data field defined as CHAR in the control file merely tells SQL*Loader how tocreate the row insert. The data could then be inserted into a CHAR, VARCHAR2, NCHAR.Column 1 is defined in the database as a fixed-length CHAR column of length 5. Sothe data (aaa) is left-justified in that column, which remains five characters wide.The extraspace on the right is padded with blanks.The name of the data field corresponds to the name of the table column intowhich the data is to be loaded.The datatype of the field tells SQL*Loader how to treat thedatain the datafile (for example, bind type). It is not the same as the column datatype.SQL*Loader input datatypes are independent of the column datatype.Data is converted from thedatatypespecified in the control file to the datatype of the column in the database.SQL*Loader converts data stored in VARRAYs before storing the VARRAY data.The bad file contains records that were rejected, either by SQL*Loader or by Oracle.Some of the possible reasons for rejection are discussed in the next sections.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.

Share & Embed

More from this user

Add a Comment

Characters: ...