SQLLoader.docx

上传人:b****8 文档编号:11243408 上传时间:2023-02-26 格式:DOCX 页数:72 大小:116.02KB
下载 相关 举报
SQLLoader.docx_第1页
第1页 / 共72页
SQLLoader.docx_第2页
第2页 / 共72页
SQLLoader.docx_第3页
第3页 / 共72页
SQLLoader.docx_第4页
第4页 / 共72页
SQLLoader.docx_第5页
第5页 / 共72页
点击查看更多>>
下载资源
资源描述

SQLLoader.docx

《SQLLoader.docx》由会员分享,可在线阅读,更多相关《SQLLoader.docx(72页珍藏版)》请在冰豆网上搜索。

SQLLoader.docx

SQLLoader

10SQL*LoaderFieldListReference

Thischapterdescribesthefield-listportionoftheSQL*Loadercontrolfile.Thefollowingtopicsarediscussed:

∙FieldListContents

∙SpecifyingthePositionofaDataField

∙SpecifyingColumnsandFields

∙SQL*LoaderDatatypes

∙SpecifyingFieldConditions

∙UsingtheWHEN,NULLIF,andDEFAULTIFClauses

∙LoadingDataAcrossDifferentPlatforms

∙ByteOrdering

∙LoadingAll-BlankFields

∙TrimmingWhitespace

∙HowthePRESERVEBLANKSOptionAffectsWhitespaceTrimming

∙ApplyingSQLOperatorstoFields

∙UsingSQL*LoadertoGenerateDataforInput

FieldListContents

Thefield-listportionofaSQL*Loadercontrolfileprovidesinformationaboutfieldsbeingloaded,suchasposition,datatype,conditions,anddelimiters.

Example10-1showsthefieldlistsectionofthesamplecontrolfilethatwasintroducedinChapter9.

Example10-1FieldListSectionofSampleControlFile

.

.

.

1(hiredateSYSDATE,

2deptnoPOSITION(1:

2)INTEGEREXTERNAL

(2)

NULLIFdeptno=BLANKS,

3jobPOSITION(7:

14)CHARTERMINATEDBYWHITESPACE

NULLIFjob=BLANKS"UPPER(:

job)",

mgrPOSITION(28:

31)INTEGEREXTERNAL

TERMINATEDBYWHITESPACE,NULLIFmgr=BLANKS,

enamePOSITION(34:

41)CHAR

TERMINATEDBYWHITESPACE"UPPER(:

ename)",

empnoPOSITION(45)INTEGEREXTERNAL

TERMINATEDBYWHITESPACE,

salPOSITION(51)CHARTERMINATEDBYWHITESPACE

"TO_NUMBER(:

sal,'$99,999.99')",

4commINTEGEREXTERNALENCLOSEDBY'('AND'%'

":

comm*100"

Inthissamplecontrolfile,thenumbersthatappeartotheleftwouldnotappearinarealcontrolfile.Theyarekeyedinthissampletotheexplanatorynotesinthefollowinglist:

1.SYSDATEsetsthecolumntothecurrentsystemdate.See"SettingaColumntotheCurrentDate".

2.POSITIONspecifiesthepositionofadatafield.See"SpecifyingthePositionofaDataField".

INTEGEREXTERNAListhedatatypeforthefield.See"SpecifyingtheDatatypeofaDataField"and"NumericEXTERNAL".

TheNULLIFclauseisoneoftheclausesthatcanbeusedtospecifyfieldconditions.See"UsingtheWHEN,NULLIF,andDEFAULTIFClauses".

Inthissample,thefieldisbeingcomparedtoblanks,usingtheBLANKSparameter.See"ComparingFieldstoBLANKS".

3.TheTERMINATEDBYWHITESPACEclauseisoneofthedelimitersitispossibletospecifyforafield.See"SpecifyingDelimiters".

4.TheENCLOSEDBYclauseisanotherpossiblefielddelimiter.See"SpecifyingDelimiters".

SpecifyingthePositionofaDataField

Toloaddatafromthedatafile,SQL*Loadermustknowthelengthandlocationofthefield.Tospecifythepositionofafieldinthelogicalrecord,usethePOSITIONclauseinthecolumnspecification.Thepositionmayeitherbestatedexplicitlyorrelativetotheprecedingfield.ArgumentstoPOSITIONmustbeenclosedinparentheses.Thestart,end,andintegervaluesarealwaysinbytes,evenifcharacter-lengthsemanticsareusedforadatafile.

Thesyntaxforthepositionspecification(pos_spec)clauseisasfollows:

Descriptionoftheillustrationpos_spec.gif

Table10-1describestheparametersforthepositionspecificationclause.

Table10-1ParametersforthePositionSpecificationClause

Parameter

Description

start

Thestartingcolumnofthedatafieldinthelogicalrecord.Thefirstbytepositioninalogicalrecordis1.

end

Theendingpositionofthedatafieldinthelogicalrecord.Eitherstart-endorstart:

endisacceptable.Ifyouomitend,thenthelengthofthefieldisderivedfromthedatatypeinthedatafile.NotethatCHARdataspecifiedwithoutstartorend,andwithoutalengthspecification(CHAR(n)),isassumedtohavealengthof1.Ifitisimpossibletoderivealengthfromthedatatype,thenanerrormessageisissued.

*

Specifiesthatthedatafieldfollowsimmediatelyafterthepreviousfield.Ifyouuse*forthefirstdatafieldinthecontrolfile,thenthatfieldisassumedtobeatthebeginningofthelogicalrecord.Whenyouuse*tospecifyposition,thelengthofthefieldisderivedfromthedatatype.

+integer

Youcanuseanoffset,specifiedas+integer,tooffsetthecurrentfieldfromthenextpositionaftertheendofthepreviousfield.Anumberofbytes,asspecifiedby+integer,areskippedbeforereadingthevalueforthecurrentfield.

YoumayomitPOSITIONentirely.Ifyoudo,thenthepositionspecificationforthedatafieldisthesameasifPOSITION(*)hadbeenused.

UsingPOSITIONwithDataContainingTabs

Whenyouaredeterminingfieldpositions,bealertfortabsinthedatafile.SupposeyouusetheSQL*LoaderadvancedSQLstringcapabilitiestoloaddatafromaformattedreport.Youwouldprobablyfirstlookataprintedcopyofthereport,carefullymeasureallcharacterpositions,andthencreateyourcontrolfile.Insuchasituation,itishighlylikelythatwhenyouattempttoloadthedata,theloadwillfailwithmultiple"invalidnumber"and"missingfield"errors.

Thesekindsoferrorsoccurwhenthedatacontainstabs.Whenprinted,eachtabexpandstoconsumeseveralcolumnsonthepaper.Inthedatafile,however,eachtabisstillonlyonecharacter.Asaresult,whenSQL*Loaderreadsthedatafile,thePOSITIONspecificationsarewrong.

Tofixtheproblem,inspectthedatafilefortabsandadjustthePOSITIONspecifications,orelseusedelimitedfields.

SeeAlso:

"SpecifyingDelimiters"

UsingPOSITIONwithMultipleTableLoads

Inamultipletableload,youspecifymultipleINTOTABLEclauses.WhenyouspecifyPOSITION(*)forthefirstcolumnofthefirsttable,thepositioniscalculatedrelativetothebeginningofthelogicalrecord.WhenyouspecifyPOSITION(*)forthefirstcolumnofsubsequenttables,thepositioniscalculatedrelativetothelastcolumnofthelasttableloaded.

Thus,whenasubsequentINTOTABLEclausebegins,thepositionisnotsettothebeginningofthelogicalrecordautomatically.ThisallowsmultipleINTOTABLEclausestoprocessdifferentpartsofthesamephysicalrecord.Foranexample,see"ExtractingMultipleLogicalRecords".

Alogicalrecordmightcontaindataforoneoftwotables,butnotboth.Inthiscase,youwouldresetPOSITION.InsteadofomittingthepositionspecificationorusingPOSITION(*+n)forthefirstfieldintheINTOTABLEclause,usePOSITION

(1)orPOSITION(n).

ExamplesofUsingPOSITION

siteidPOSITION(*)SMALLINT

sitelocPOSITION(*)INTEGER

Ifthesewerethefirsttwocolumnspecifications,thensiteidwouldbeginincolumn1,andsitelocwouldbegininthecolumnimmediatelyfollowing.

enamePOSITION(1:

20)CHAR

empnoPOSITION(22-26)INTEGEREXTERNAL

allowPOSITION(*+2)INTEGEREXTERNALTERMINATEDBY"/"

Columnenameischaracterdatainpositions1through20,followedbycolumnempno,whichispresumablynumericdataincolumns22through26.Columnallowisoffsetfromthenextposition(27)aftertheendofempnoby+2,soitstartsincolumn29andcontinuesuntilaslashisencountered.

SpecifyingColumnsandFields

Youmayloadanynumberofatable'scolumns.Columnsdefinedinthedatabase,butnotspecifiedinthecontrolfile,areassignednullvalues.

Acolumnspecificationisthenameofthecolumn,followedbyaspecificationforthevaluetobeputinthatcolumn.Thelistofcolumnsisenclosedbyparenthesesandseparatedwithcommasasfollows:

(columnspec,columnspec,...)

Eachcolumnname(unlessitismarkedFILLER)mustcorrespondtoacolumnofthetablenamedintheINTOTABLEclause.AcolumnnamemustbeenclosedinquotationmarksifitisaSQLorSQL*Loaderreservedword,containsspecialcharacters,oriscasesensitive.

IfthevalueistobegeneratedbySQL*Loader,thenthespecificationincludestheRECNUM,SEQUENCE,orCONSTANTparameter.See"UsingSQL*LoadertoGenerateDataforInput".

Ifthecolumn'svalueisreadfromthedatafile,thenthedatafieldthatcontainsthecolumn'svalueisspecified.Inthiscase,thecolumnspecificationincludesacolumnnamethatidentifiesacolumninthedatabasetable,andafieldspecificationthatdescribesafieldinadatarecord.Thefieldspecificationincludesposition,datatype,nullrestrictions,anddefaults.

Itisnotnecessarytospecifyallattributeswhenloadingcolumnobjects.AnymissingattributeswillbesettoNULL.

SpecifyingFillerFields

Afillerfield,specifiedbyBOUNDFILLERorFILLERisadatafilemappedfieldthatdoesnotcorrespondtoadatabasecolumn.Fillerfieldsareassignedvaluesfromthedatafieldstowhichtheyaremapped.

Keepthefollowinginmindregardingfillerfields:

∙Thesyntaxforafillerfieldissameasthatforacolumn-basedfield,exceptthatafillerfield'snameisfollowedbyFILLER.

∙Fillerfieldshavenamesbuttheyarenotloadedintothetable.

∙Fillerfieldscanbeusedasargumentstoinit_specs(forexample,NULLIFandDEFAULTIF).

∙Fillerfieldscanbeusedasargumentstodirectives(forexample,SID,OID,REF,andBFILE).

Toavoidambiguity,ifaFillerfieldisreferencedinadirective,suchasBFILE,andthatfieldisdeclaredinthecontrolfileinsideofacolumnobject,thenthefieldnamemustbequalifiedwiththenameofthecolumnobject.Thisisillustratedinthefollowingexample:

LOADDATA

INFILE*

INTOTABLEBFILE1O_TBLREPLACE

FIELDSTERMINATEDBY','

emp_numberchar,

emp_info_bcolumnobject

bfile_nameFILLERchar(12),

emp_bBFILE(constant"SQLOP_DIR",emp_info_b.bfile_name)NULLIF

emp_info_b.bfile_name='NULL'

BEGINDATA

00001,bfile1.dat,

00002,bfile2.dat,

00003,bfile3.dat,

∙FillerfieldscanbeusedinfieldconditionspecificationsinNULLIF,DEFAULTIF,andWHENclauses.However,theycannotbeusedinSQLstrings.

∙FillerfieldspecificationscannotcontainaNULLIForDEFAULTIF

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > PPT模板 > 简洁抽象

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1