P. 1
SQL Loader

SQL Loader

|Views: 36|Likes:
Published by venuoracle9
SQL Loader
SQL Loader

More info:

Published by: venuoracle9 on Feb 26, 2013
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PPT, PDF, TXT or read online from Scribd
See more
See less

11/20/2013

pdf

text

original

Basic Concepts

1

Sql *Loader

It is a high speed data loading utility supplied by Oracle that loads data from external files into table in an Oracle Database. It can accepts data in variety of formats, can perform transformation, filtering and can load into multiple tables from multiple files in same loading session
2

Requirements- For Sql *Loader

Tables to be loaded must already exists in the Database. SQL *Loader never creates tables, it loads existing tables. Table may be empty or may already contain data. Privileges: INSERT privilege DELETE privilege, when using REPLACE or TRUNCATE insert option
3

ctl file Data File ...dat file Log File .Files used in Sql *Loader      Control File ..dis file 4 ...bad file Discard File .log file Bad File .

Control File It controls the Behavior of Sql *Loader Source of Data to be loaded Destination of Data to be loaded Filtering of Data before Loading Transformation of Data before Loading Relating the Data file fields to table columns 5 .

Data. no: of rows rejected because of errors. Discard file Name. Bad. Message indicating when records have been discarded. Summary of the Load (no: of records read from file. Detailed breakdown of the fields & datatypes in data file that was loaded. no: of rows discarded & elapsed time of load) 6 . Error Message for records that cause error. Values of several command line parameters.Log File       It is a record of SQL *Loader‟s activities during a load session Control.

7 . it is optional. if any one error occurred. SQL *Loader will create the bad file and write the offending input records into it. it is optional Discard File – Contains the data that are discarded by „when‟ clause in control file.   Data File – Contains the data to be loaded. Bad File – Contains the data which are not loaded due to some errors. it is not optional.

SQL *Loader Overview Input Data File Control File Log File SQL *Loader Bad File Discard File DataBase 8 .

Loading Method Basically there are 3 Loading Methods Conventional Path Load Direct Path Load External Table Load( from Oracle 9i). 9 .

Conventional Path Load  Bind Array (Row Insert) is created by Sql *Loader based on field specification in control file Data from the Bind Array are then insert into the table by the DB server. if data satisfies with the corresponding column datatype 10  .

Direct Path Load      Parses the data according to the field specification in Control File Converts the data to Column datatype (not to field datatype in .ctl file) and builds Column array. 11 . Column array is passed to block formatter Newly formatted blocks are directly written directly to the database file bypassing most SQL Processing PARALLEL loading is possible.

reduce the time for loading 12 .PARALLEL Loading    Setup has to done. as the text file must be broken into several smaller files We can run several SQLLDR session in parallel for each broken data files It will increase the performance.

LOB(CLOB.NCLOB. VARRAY). BFILE) 13 .BLOB. Collection Types (Nested Table.Advantage & Disadvantage of Direct Path Load  Advantage : Very High Speed Disadvantage : Cannot Load Object Types.

Field Conversion Field 1 DATA FILE Field 2 a a a CHAR(5) Ctrl File Spec b b b CHAR(5) SQL LOADER BIND ARRAY aaa Table bbb DATABASE Column 1 Column 2 SERVER a a a_ _ CHAR(5) Column Data Type bbb VARCHAR(5) 14 .

Record Filtering Record in Data file Read in Database Control file SQL *Loader Field Processing Accepted Bad File Selected Inserted Discard Discarded File SQL *Loader When-clause Evaluation Database Server 15 .

16 .

dat' replace into table sampledata fields terminated by X'09' ( n2. Name Null Type ------------------------------. N1 N2 ------------------------.-------.Mapping between data fields in control file and columns of the table SQL> desc sampledata.---3456 12 0111 7891 3333 1234 17 .---N1 VARCHAR2(25) N2 VARCHAR2(25) LOAD DATA INFILE '/u01/xxvis/data1. n1 ) 12 7891 1234 3456 0111 3333 SQL> select * from sampledata.

ctl load data $ sqlldr control=control1.ctl userid=apps/secretone infile * into table sql_ldr1 REPLACE ( n position(1:2) ) Sql_ldr1 begindata N 3 3 4 4 5 5 6 6 7 7 18 .Data with in Control File control1.

ctl load data infile 'data2.dat' insert into table sql_ldr2 replace ( n1 position(1:3).Data in DATA file data2. n3 position(9:11) ) .ctl userid=apps/secretone Sql_ldr2: N1 N2 N3 111 222 666 333 444 666 555 666 666 777 888 666 999 000 666 19 control2.dat 111 222 666 333 444 666 555 666 666 777 888 666 999 000 666 $ sqlldr control=control2. n2 position(5:7).

--------111 222 666 333 444 666 555 666 666 777 888 666 999 0 666 data3.--------111 222 666 333 444 666 555 666 666 777 888 666 999 0 666 111 222 666 333 444 666 555 666 666 777 888 666 999 0 666 20 . n3 position(9:11) ) Sql_ldr3 ( After Loading): --------------------------------N1 N2 N3 -----.dat 111 222 666 333 444 666 555 666 666 777 888 666 999 000 666 control3.--------.--------.Appending to a table Sql_ldr3 ( Before Loading): --------------------------------N1 N2 N3 -----. n2 position(5:7).ctl load data infile 'data3.dat' insert into table sql_ldr3 append ( n1 position(1:3).

ctl load data infile 'data4.ctl userid=apps/secretone $ sqlldr control=control4.dis 333 444 333 444 21 .Loading the Selected data data4.ctl userid=apps/secretone dicard = data4.dat 111 222 333 444 111 222 333 444 111 222 $ sqlldr control=control4.dat' insert into table sql_ldr4 when n2 = '222' ( n1 position(1:3).dis control4. n2 position(5:7) ) Sql_ldr4: N1 N2 --------.--------111 222 111 222 111 222 data4.

' ( n1 integer external. 3333.dat' insert into table sql_ldr5 replace when n2='2222' fields terminated by '. n2 integer external ) Sql_ldr5 N1 N2 -------.2222.dat 1111. 1111.4444. 1111.4444.2222. $ sqlldr control=control5. 3333.Field Separator data5.--------1111 2222 1111 2222 1111 2222 22 .ctl load data infile 'data5.ctl userid=apps/secretone control5.2222.

ctl userid=apps/secretone load data 33 44 infile 'data91.dat' 55 66 Sql_ldr9 infile 'data92. 77 88 n2 position(4:5) 99 0 ) 11 11 23 .ctl 11 22 $ sqlldr control=control2.dat insert into N1 N2 77 88 table sql_ldr9 11 22 99 00 replace 33 44 11 11 ( 55 66 n1 position(1:2).dat control9.dat' data92.Loading Multiple Data Files data91.

ctl userid=apps/secretone control10.dat 11 22 33 44 55 66 $ sqlldr control=control10.dat' insert into table sql_ldr101 replace (n1 position(1:2).ctl load data infile 'data10. n2 position(4:5)) Sql_ldr101 N1 11 33 55 N2 22 44 66 Sql_ldr102 N1 11 33 55 N2 22 44 66 24 .Loading into Multiple Tables data10. n2 position(4:5)) into table sql_ldr102 replace (n1 position(1:2).

N1 N2 N1 N2 99 99 11 22 11 22 n2 position(4:5)) 33 44 33 44 into 55 66 55 66 table sql_ldr112 replace 77 88 77 88 (n1 position(1:2).ctl userid=apps/secretone load data 33 44 infile 'data111.dat' Sql_ldr111 Sql_ldr101 data112.ctl 11 22 $ sqlldr control=control11.dat insert into table sql_ldr111 replace 77 88 99 11 (n1 position(1:2).Loading from Multiple Data files to Multiple Tables data111.dat' 55 66 infile 'data112.dat control11. 99 11 99 11 n2 position(4:5)) 99 99 99 99 25 .

dat' insert into table sql_ldr2 replace ( n1 position(1:3).dat 111 222 666 333 444 666 555 666 666 777 888 666 999 000 666 $ sqlldr control=control2. n3 position(9:11) ) Sql_ldr2 N1 N2 N3 555 666 666 777 888 666 999 000 666 26 .ctl userid=apps/secretone skip=2 control2.Skipping records data2.ctl load data infile 'data2. n2 position(5:7).

Using LOAD option data14. a2 char(3) ) Sql_ldr14: A1 A2 aa cc bbb ddd 27 .dat' into table sql_ldr14 truncate/replace ( a1 char(2).dat aabbb ccddd $ sqlldr control=control14.ctl load data infile 'data14.ctl userid=apps/secretone LOAD = 2 eefff control14.

dat load data infile 'data12.0111.dat' "fix 5" insert into table sql_ldr12 replace fields terminated by '.3456.ctl userid=apps/secretone Sql_ldr12: N1 N2 12 56 91 34 78 1 28 .dat 12.' ( n1 integer external.2 control12.7891.Fixed Record Format data12. n2 integer external ) $ sqlldr control=control12.

ctl userid=apps/secretone infile „data1.bbb08ccc.ctl load data $ sqlldr control=control1. ccc dddd a2 char ee ff ).dat 07aaa. Desc sql_ldr1 a1 Varchar2(10) a2 Varchar2(10) 29 .‟ A1 A2 ( aaa bbb a1 char.Variable Record Format data1.ff control1.dat‟ “var 02” Sql_ldr11: into table sql_ldr1 fields terminated by „.dddd05ee.

eeee ffff a2 char ) 30 .bbb|ccc.dat‟ “str „|‟” into table sql_ldr2 A1 A2 fields terminated by „.‟ aaa bbb ( ccc dddd a1 char.dddd|eeee.dat aaa.ffff| Desc sql_ldr1 a1 Varchar2(10) a2 Varchar2(10) Control2.ctl userid=apps/secretone load data Sql_ldr12: infile „data2.Stream Record Format data2.ctl $ sqlldr control=control2.

Command Line Parameters  BAD .Specifies the file where all discarded data is kept 31 .Specifies the file that contains all data to be loaded. DIRECT .bad extension.Specifies the file in which all bad data is kept.   DISCARD . The default filename is the control filename with a .Specifies the name of control file.Size of the bind array in bytes. System dependent. Otherwise Conventional Path will be used. CONTROL .    DATA . BINDSIZE .If set to TRUE Direct Path Load is used. Default value is FALSE.

The Default filename is control_filename.Command Line Parameters  DISCARDMAX – The maximum no: of invalid records. which is not satisfying the „when‟ clause in control file. ERRORS – Specifies how many total errors can be encountered before SQL *Loader session is to stop. Default value is 50. Default value is ALL.log. where information on success or failure of the Loading session is reported. LOG – Specifies the log file‟s name.    32 . that may be encountered before SQL *Loader session is stop. Default Value is ALL. LOAD – Specifies the maximum no: of records to load before stopping.

33  . SKIP – No: of record to skip before starting the load. This parameter is important for restarting a load process after stopping an earlier session. For Direct path load. loads are performed in parallel where possible.Command Line Parameters  PARALLEL – If set to TRUE. Default value is 64 in Conventional Path. for Conventional path load. ROWS specifies the no: of rows to read before a data save is performed.   ROWS – No: of rows to put in the path bind array. Default value is FALSE PARFILE – An additional file that contains more parameter specification. Useful in Recovery from failure.

34 . when loading a direct path load of a partitioned table.Command Line Parameters   USERID – Specifies the username and password for the user conducting the SQL *Loader session SILENT – Allows to suppress various header and feedback messages that SQL *Loader normally displays during a Load session. Keyword for use with SILENT parameter • • • • • DISCARDS – Suppresses the discarded messages ERRORS – Suppresses the error message FEEDBACK – Suppresses the “commit point reached” messages. PARTITION – Suppresses the per-partition statistics. HEADER – Suppresses the messages that SQL *Loader displays on the screen when we first launch the executable.

35 .

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->