Sie sind auf Seite 1von 5

What is SQL*Loader and what is it used for?

SQL*Loader is a bulk loader utility used for moving data from external files into
the Oracle database. ts syntax is similar to that of the !"# Load utility$ but
comes with more o%tions. SQL*Loader su%%orts various load formats$ selective
loading$ and multi&table loads.
'ow does one use the SQL*Loader utility?
One can load data into an Oracle database by using the s(lldr )s(lload on some
%latforms* utility. nvoke the utility without arguments to get a list of available
%arameters. Look at the following exam%le+
s(lldr scott,tiger control-loader.ctl
.his sam%le control file )loader.ctl* will load an external data file containing
delimited data+ load data
infile /c+0data0mydata.csv/
into table em% ) em%no$ em%name$ sal$ de%tno *
fields terminated by 1$1 o%tionally enclosed by /1/
.he mydata.csv file may look like this+
23332$1Scott .iger1$ 2333$ 43
2333#$15rank 6aude1$ 733$ #3
8nother Sam%le control file with in&line data formatted as fix length records.
.he trick is to s%ecify 1*1 as the name of the data file$ and use "9:6!8.8 to
start the data section in the control file.
load data
infile *
re%lace
into table de%artments
) de%t %osition )3#+37* char)4*$
de%tname %osition )3;+#<* char)#3* *
begindata
=OS= =O>?@.9A S=96=9
96:L 96:LS' L.9A8.@A9
>8.' >8.'9>8.=S
?OLB ?OL.=8L S=96=9
s there a SQL*@nloader to download data to a flat file?
Oracle does not su%%ly any data unload utilities. 'owever$ you can use SQL*?lus
to select and format your data and then s%ool it to a file+
set echo off new%age 3 s%ace 3 %agesiCe 3 feed off head off trims%ool on
s%ool oradata.txt
select col2 /$/ col# /$/ colD
from tab2
where col# - /EBF/G
s%ool off
8lternatively use the @.LH5L9 ?L,SQL %ackage+
Aemember to u%date initS!.ora$ utlHfileHdir-/c+0oradata/ %arameter
declare
f% utlHfile.fileHty%eG
begin
f% +- utlHfile.fo%en)/c+0oradata/$/tab2.txt/$/w/*G
utlHfile.%utf)f%$ /Is$ Is0n/$ /.ext5ield/$ 77*G
utlHfile.fclose)f%*G
endG
,
Bou might also want to investigate third %arty tools like .O8! or >anage. 5ast
@nloader from =8 to hel% you unload data from Oracle.
=an one load variable and fix length data records?
Bes$ look at the following control file exam%les. n the first we will load
delimited data )variable length*+
LO8! !8.8
65L9 *
6.O .8"L9 loadHdelimitedHdata
59L!S .9A>68.9! "B 1$1 O?.O68LLB 96=LOS9! "B /1/
.A8L6: 6@LL=OLS
) data2$ data# *
"9:6!8.8
22222$8888888888
#####$18$"$=$!$1
f you need to load %ositional data )fixed length*$ look at the following control
file exam%le+ LO8! !8.8
65L9 *
6.O .8"L9 loadH%ositionalHdata
) data2 ?OS.O6)2+7*$
data# ?OS.O6)J+27* *
"9:6!8.8
222228888888888
#####""""""""""
=an one ski% header records load while loading?
@se the 1SK? n1 keyword$ where n - number of logical rows to ski%. Look at this
exam%le+ LO8! !8.8
65L9 *
6.O .8"L9 loadH%ositionalHdata
SK? 7
) data2 ?OS.O6)2+7*$
data# ?OS.O6)J+27* *
"9:6!8.8
222228888888888
#####""""""""""
=an one modify data as it loads into the database?
!ata can be modified as it loads into the Oracle !atabase. 6ote that this only
a%%lies for the conventional load %ath and not for direct %ath loads.
LO8! !8.8
65L9 *
6.O .8"L9 modifiedHdata
) recHno 1myHdbHse(uence.nextval1$
region =O6S.86. /D2/$
timeHloaded 1toHchar)SBS!8.9$ /''#4+>/*1$
data2 ?OS.O6)2+7* 1+data2,2331$
data# ?OS.O6)J+27* 1u%%er)+data#*1$
dataD ?OS.O6)2J+##*1toHdate)+dataD$ /BB>>!!/*1 *
"9:6!8.8
222228888888888LL2#32
#####""""""""""LL322#
LO8! !8.8
65L9 /mailHorders.txt/
"8!5L9 /badHorders.txt/
8??96!
6.O .8"L9 mailingHlist
59L!S .9A>68.9! "B 1$1
) addr$
city$
state$
Ci%code$
mailingHaddr 1decode)+mailingHaddr$ null$ +addr$ +mailingHaddr*1$
mailingHcity 1decode)+mailingHcity$ null$ +city$ +mailingHcity*1$
mailingHstate *
=an one load data into multi%le tables at once?
Look at the following control file+
LO8! !8.8
65L9 *
A9?L8=9
6.O .8"L9 em%
W'96 em%no M- / /
) em%no ?OS.O6)2+4* 6.9:9A 9E.9A68L$
ename ?OS.O6)J+27* ='8A$
de%tno ?OS.O6)2<+2;* ='8A$
mgr ?OS.O6)#3+#D* 6.9:9A 9E.9A68L *
6.O .8"L9 %roN
W'96 %roNno M- / /
) %roNno ?OS.O6)#7+#<* 6.9:9A 9E.9A68L$
em%no ?OS.O6)2+4* 6.9:9A 9E.9A68L *
=an one selectively load only the records that one need?
Look at this exam%le$ )32* is the first character$ )D3+D<* are characters D3 to
D<+
LO8! !8.8
65L9 /mydata.dat/
"8!5L9 /mydata.bad/
!S=8A!5L9 /mydata.dis/
8??96!
6.O .8"L9 myHselectiveHtable
W'96 )32* OP /'/ and )32* OP /./ and )D3+D<* - /2LLL2#2</
) region =O6S.86. /D2/$
serviceHkey ?OS.O6)32+22* 6.9:9A 9E.9A68L$
callHbHno ?OS.O6)2#+#L* ='8A *
=an one ski% certain columns while loading data?
One cannot use ?OS.O6)x+y* with delimited data. Luckily$ from Oracle ;i one
can s%ecify 5LL9A columns. 5LL9A columns are used to ski% columns,fields in
the load file$ ignoring fields that one does not want. Look at this exam%le+
LO8! !8.8
.A@6=8.9
6.O .8"L9 .2
59L!S .9A>68.9! "B /$/
) field2$
field# 5LL9A$
fieldD *
'ow does one load multi&line records?
One can create one logical record from multi%le %hysical records using one of
the following two clauses+
=O6=8.968.9+ & use when SQL*Loader should combine the same number of
%hysical records together to form one logical record.
=O6.6@95 & use if a condition indicates that multi%le records should be
treated as one. 9g. by having a /Q/ character in column 2.
'ow can get SQL*Loader to =O>>. only at the end of the load file?
One cannot$ but by setting the AOWS- %arameter to a large value$ committing
can be reduced. >ake sure you have big rollback segments ready when you use
a high value for AOWS-.
=an one im%rove the %erformance of SQL*Loader?
8 very sim%le but easily overlooked hint is not to have any indexes and,or
constraints )%rimary key* on your load tables during the load %rocess. .his will
significantly slow down load times even with AOWS- set to a high value.
8dd the following o%tion in the command line+ !A9=.-.A@9. .his will
effectively by%ass most of the A!">S %rocessing. 'owever$ there are cases
when you can/t use direct load. Aefer to cha%ter ; on Oracle server @tilities
manual.
.urn off database logging by s%ecifying the @6A9=OR9A8"L9 o%tion. .his o%tion
can only be used with direct data loads.
Aun multi%le load Nobs concurrently.
What is the difference between the conventional and direct %ath loader?
.he conventional %ath loader essentially loads the data by using standard
6S9A. statements. .he direct %ath loader )!A9=.-.A@9* by%asses much of
the logic involved with that$ and loads directly into the Oracle data files. >ore
information about the restrictions of direct %ath loading can be obtained from
the @tilities @sers :uide.

Das könnte Ihnen auch gefallen