sqlldr

Upload: narender-reddy

Post on 03-Jun-2018

218 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/12/2019 sqlldr

    1/10

    SQL*Loader Features

    SQL*Loader loads data from external files into tables of an Oracle database. It has a powerful dataparsing engine that puts little limitation on the format of the data in the datafile. You can useSQL*Loader to do the following:

    Load data across a network if our data files are on a different sstem 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 sstem#s file sstem to access the datafiles.

    Load data from disk& tape& or named pipe.

    'enerate sophisticated error reports& which greatl aid troubleshooting.

    Load arbitraril complex obect+relational data.

    )se secondar datafiles for loading LO,s and collections.

    tpical 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.

    http://docs.oracle.com/cd/B28359_01/server.111/b28319/ldr_concepts.htm#i1007641http://docs.oracle.com/cd/B28359_01/server.111/b28319/ldr_concepts.htm#i1007641
  • 8/12/2019 sqlldr

    2/10

    SQL*Loader Parameters

    SQL*Loader is in!oked when ou specif the sqlldrcommand and& optionall& parameters that

    establish session characteristics.

    In situations where ou alwas use the same parameters for which the !alues seldom change& it can bemore 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 theparameter file on the command line using the PARFILEparameter.

    3ertain parameters can also be specified within the SQL*Loader control file b using theOPTIONSclause.

    2arameters specified on the command line o!erride an parameter !alues specified in a parameter fileor OPTIONSclause.

    PARFILE (parameter file)

    4efault: none

    PARFILEspecifies the name of a file that contains commonl used command+line parameters. /or

    example& a parameter file named daily_report.parmight ha!e the following contents:

    USERID=scottCONTROL=daily_report.ctlERRORS=9999LO=daily_report.lo!

    /or securit reasons& ou should not include our USERIDpassword in a parameter file. SQL*Loader

    will prompt ou for the password after ou specif the parameter file at the command line& forexample:

    sqlldr PARFILE=daily_report.parPass#ord$ pass#ord

    SQL*Loader Control File

    -he control file is a text file written in a language that SQL*Loader understands. -he control file tellsSQL*Loader where to find the data& how to parse and interpret the data& where to insert the data& andmore.

    lthough not precisel defined& a control file can be said to ha!e three sections.

    -he first section contains session+wide information& for example: 'lobal options such as bindsi5e& rows& records to skip& and so on

    INFILEclauses to specif where the input data is located

    4ata to be loaded-he second section consists of one or more INTO TA%LEblocks. 6ach of these blocks contains

    information about the table into which the data is to be loaded& such as the table name and the columnsof the table.

    -he third section is optional and& if present& contains input data.

  • 8/12/2019 sqlldr

    3/10

    Some control file sntax considerations to keep in mind are:

    -he sntax 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 takenliterall& including case.

    In control file sntax& comments extend from the two hphens "++$ that mark the beginning of

    the comment to the end of the line. -he optional third section of the control file is interpreted asdata rather than as control file sntax7 conse(uentl& comments in this section are not supported.

    -he kewords CONSTANTand &ONEha!e special meaning to SQL*Loader and are therefore

    reser!ed. -o a!oid potential conflicts& Oracle recommends that ou do not use eitherCONSTANTor &ONEas a name for an tables or columns.

    Control File Contents

    -he SQL*Loader control file is a text file that contains data definition language "44L$ instructions.44L is used to control the following aspects of a SQL*Loader session:

    8here SQL*Loader will find the data to load

    9ow SQL*Loader expects that data to be formatted

    9ow SQL*Loader will be configured "memor management& reecting records& interrupted loadhandling& and so on$ as it loads the data

    9ow SQL*Loader will manipulate the data being loaded

    Specifying atafiles

    -o specif a datafile that contains the data to be loaded& use the INFILEkeword& followed b the

    filename and optional file processing options string. You can specif multiple files b using multipleINFILEkewords.

    E!amples of I"FILE Synta!

    -he following list shows different was ou can specif INFILEsntax:

    4ata contained in the control file itself:

    INFILE '

    4ata contained in a file named sa(plewith a default extension of .dat$

    INFILE sa(ple

    4ata contained in a file named data)ile.datwith a full path specified:

    INFILE *c$+topdir+s,-dir+data)ile.dat*

  • 8/12/2019 sqlldr

    4/10

    pecifying #ultiple atafiles

    -o load data from multiple datafiles in one SQL*Loader run& use an INFILEclause for each datafile.

    4atafiles need not ha!e the same file processing options& although the laout of the records must beidentical. /or example& two files could be specified with completel different file processing optionsstrings& and a third could consist of data in the control file.

    You can also specif a separate discard file and bad file for each datafile. In such a case& the separatebad files and discard files must be declared immediatel after each datafile name. /or example& thefollowing excerpt from a control file specifies four datafiles with separate bad and discard files:

    INFILE (ydat.dat %ADFILE (ydat.-ad DISCARDFILE (ydat.disINFILE (ydat/.datINFILE (ydat0.dat DISCARDFILE (ydat0.disINFILE (ydat1.dat DISCARD2A3 4 4

    /or (ydat.dat5both a bad file and discard file are explicitl specified. -herefore both files

    are created& as needed.

    /or (ydat/.dat5neither 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.dat5the default bad file is created& if needed. discard file with the specified

    name "(ydat0.dis$ is created& as needed.

    /or (ydat1.dat5the 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 defaultname (ydat1.dsc.

    Identifying ata in t$e Control File %it$ &E'I"AA

    If the data is included in the control file itself& then the INFILEclause is followed b an asterisk rather

    than a filename. -he actual data is placed in the control file after the load configuration specifications.

    Specif the %EINDATAstatement before the first data record. -he sntax is:

    %EINDATAdata

    eep the following points in mind when using the %EINDATAstatement:

    If ou omit the %EINDATAstatement 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 %EINDATAstatement.

    4o not use spaces or other characters on the same line as the %EINDATAstatement& or the line

    containing %EINDATAwill be interpreted as the first line of data.

    4o not put comments after %EINDATA5or the will also be interpreted as data.

    Specifying atafile Format and &uffering

    8hen configuring SQL*Loader& ou can specif an operating sstem+dependent file processing options

  • 8/12/2019 sqlldr

    5/10

    string "os_)ile_proc_cla,se$ in the control file to specif file format and buffering.

    /or example& suppose that our operating sstem has the following option+string sntax:

    4escription of the illustration recsi5e;spec.gif

    In this sntax& RECSI&Eis the si5e of a fixed+length record& and %UFFERSis the number of buffers touse for asnchronous I+bte records and instruct SQL*Loader

    to use = I

  • 8/12/2019 sqlldr

    6/10

    Criteria for Reected Records

    record can be reected for the following reasons:

    1. )pon insertion& the record causes an Oracle error "such as in!alid data for a gi!en datatpe$.

    @. -he record is formatted incorrectl so that SQL*Loader cannot find field boundaries.

    A. -he record !iolates a constraint or tries to make a uni(ue index non+uni(ue.

    If the data can be e!aluated according to the :;ENclause criteria "e!en with unbalanced delimiters$&

    then it is either inserted or reected.

    ?either a con!entional path nor a direct path load will write a row to an table if it is reected becauseof reason number @ in the pre!ious list.

    con!entional path load will not write a row to an tables if reason number 1 or A in the pre!ious listis !iolated for an one table. -he row is reected for that table and written to the reect file.

    In a con!entional path load& if the data file has a record that is being loaded into multiple tables and thatrecord is reected from at least one of the tables& then that record is not loaded into an of the tables.

    Specifying t$e iscard File

    4uring execution& SQL*Loader can create a discard file for records that do not meet an of the loadingcriteria. -he records contained in this file are called discarded records. 4iscarded records do not satisfan of the :;ENclauses specified in the control file. -hese records differ from reected records.

    4iscarded records do not necessaril ha!e an bad data. ?o insert is attempted on a discarded record.

    discard file is created according to the following rules:

    You ha!e specified a discard filename and one or more records fail to satisf all of the :;EN

    clauses specified in the control file. "If the discard file is created& it o!erwrites an existing filewith the same name& so be sure that ou do not o!erwrite an files ou wish to retain.$

    If no records are discarded& then a discard file is not created.

    -o create a discard file from within a control file& specif an of the following: DISCARDFILE

    )ile

  • 8/12/2019 sqlldr

    7/10

    the DISCARDFILEclause specifies that a discard filename follows.

    -he )ile

  • 8/12/2019 sqlldr

    8/10

    nonpartitioned table

    SQL*Loader Case Studies

    SQL*Loader features are illustrated in a !ariet of case studies. -he case studies are based upon theOracle demonstration database tables& e(pand dept& owned b the user scott. "In some case

    studies& additional columns ha!e been added.$-he case studies are numbered 1 through 11& starting withthe simplest scenario and progressing in complexit.

    -he following is a summar of the case studies:

    3ase Stud 1: Loading Bariable+Length 4ata + Loads stream format records in which the fieldsare terminated b commas and ma be enclosed b (uotation marks. -he data is found at theend of the control file.

    3ase Stud @: Loading /ixed+/ormat /ields + Loads data from a separate datafile.

    3ase Stud A: Loading a 4elimited& /ree+/ormat /ile + Loads data from stream format recordswith delimited fields and se(uence numbers. -he data is found at the end of the control file.

    3ase Stud C: Loading 3ombined 2hsical Decords + 3ombines multiple phsical records intoone logical record corresponding to one database row.

    3ase Stud E: Loading 4ata into %ultiple -ables + Loads data into multiple tables in one run.

    3ase Stud 0: Loading 4ata )sing the 4irect 2ath Load %ethod + Loads data using the directpath load method.

    3ase Stud F: 6xtracting 4ata from a /ormatted Deport + 6xtracts data from a formatted report.

    3ase Stud =: Loading 2artitioned -ables + Loads partitioned tables.

    3ase Stud G: Loading LO,/IL6s "3LO,s$ + dds a CLO%column called res,(eto the table

    e(p& uses a FILLERfield "res_)ile$& and loads multiple LO,/IL6s into the e(ptable. 3ase Stud 1>: D6/ /ields and BDDYs + Loads a customer table that has a primar ke as

    its OI4 and stores order items in a ARRA>. Loads an order table that has a reference to the

    customer table and the order items in a ARRA>.

    3ase Stud 11: Loading 4ata in the )nicode 3haracter Set + Loads data in the )nicodecharacter set& )-/10& in little+endian bte order. -his case stud uses character+lengthsemantics.

    ttp:

  • 8/12/2019 sqlldr

    9/10

    Case .ctl .dat .sql

    1 ulcase1.ctl ?

  • 8/12/2019 sqlldr

    10/10

    Substitute the appropriate control file name and log file name for the CONTROLand LO

    parameters and press 6nter. 8hen ou are prompted for a password& tpe ti!erand then press

    6nter.

    ,e sure to read the control file for an notes that are specific to the particular case stud ou areexecuting. /or example& case stud 0 re(uires that ou add DIRECT=TRUEto the SQL*Loader

    command line.