Вы находитесь на странице: 1из 50

WelcomeCarlos

(//docs.oracle.com/en/)

(#)

Home(/)/Database(/en/database/)/OracleDatabaseOnlineDocumentation11gRelease1(11.1)(../../index.htm)/
DatabaseAdministration(../../nav/portal_4.htm)

DatabaseSQLLanguageReference
Datatypes
EachvaluemanipulatedbyOracleDatabasehasadatatype.Thedatatypeofavalueassociatesafixed
setofpropertieswiththevalue.ThesepropertiescauseOracletotreatvaluesofonedatatypedifferently
fromvaluesofanother.Forexample,youcanaddvaluesofNUMBERdatatype,butnotvaluesofRAW
datatype.
Whenyoucreateatableorcluster,youmustspecifyadatatypeforeachofitscolumns.Whenyoucreate
aprocedureorstoredfunction,youmustspecifyadatatypeforeachofitsarguments.Thesedatatypes
definethedomainofvaluesthateachcolumncancontainoreachargumentcanhave.Forexample,DATE
columnscannotacceptthevalueFebruary29(exceptforaleapyear)orthevalues2or'SHOE'.Each
valuesubsequentlyplacedinacolumnassumesthedatatypeofthecolumn.Forexample,ifyouinsert
'01JAN98'intoaDATEcolumn,thenOracletreatsthe'01JAN98'characterstringasaDATEvalue
afterverifyingthatittranslatestoavaliddate.
OracleDatabaseprovidesanumberofbuiltindatatypesaswellasseveralcategoriesforuserdefined
typesthatcanbeusedasdatatypes.ThesyntaxofOracledatatypesappearsinthediagramsthatfollow.
Thetextofthissectionisdividedintothefollowingsections:

OracleBuiltinDatatypes(#i54330)
ANSI,DB2,andSQL/DSDatatypes(#i54335)
UserDefinedTypes(#i46376)
OracleSuppliedTypes(#i54873)
DatatypeComparisonRules(sql_elements002.htm#i55214)
DataConversion(sql_elements002.htm#i46862)

Adatatypeiseitherscalarornonscalar.Ascalartypecontainsanatomicvalue,whereasanonscalar
(sometimescalleda"collection")containsasetofvalues.Alargeobject(LOB)isaspecialformofscalar
datatyperepresentingalargescalarvalueofbinaryorcharacterdata.LOBsaresubjecttosome
restrictionsthatdonotaffectotherscalartypesbecauseoftheirsize.Thoserestrictionsaredocumentedin
thecontextoftherelevantSQLsyntax.

SeeAlso:
"RestrictionsonLOBColumns"(#BABHIJHI)
TheOracleprecompilersrecognizeotherdatatypesinembeddedSQLprograms.Thesedatatypesare
calledexternaldatatypesandareassociatedwithhostvariables.Donotconfusebuiltindatatypesand
userdefinedtypeswithexternaldatatypes.Forinformationonexternaldatatypes,includinghowOracle
convertsbetweenthemandbuiltindatatypesoruserdefinedtypes,seePro*COBOLProgrammer'sGuide
(../../appdev.111/b28428/toc.htm),andPro*C/C++Programmer'sGuide(../../appdev.111/b28427/toc.htm).

datatypes::=

Descriptionoftheillustrationdatatypes.gif(img_text/datatypes.htm)

Oracle_built_in_datatypes::=

Descriptionoftheillustrationoracle_built_in_datatypes.gif(img_text/oracle_built_in_datatypes.htm)

FordescriptionsoftheOraclebuiltindatatypes,referto"OracleBuiltinDatatypes"(#i54330).

character_datatypes::=

Descriptionoftheillustrationcharacter_datatypes.gif(img_text/character_datatypes.htm)

number_datatypes::=

Descriptionoftheillustrationnumber_datatypes.gif(img_text/number_datatypes.htm)

long_and_raw_datatypes::=

Descriptionoftheillustrationlong_and_raw_datatypes.gif(img_text/long_and_raw_datatypes.htm)

datetime_datatypes::=

Descriptionoftheillustrationdatetime_datatypes.gif(img_text/datetime_datatypes.htm)

large_object_datatypes::=

Descriptionoftheillustrationlarge_object_datatypes.gif(img_text/large_object_datatypes.htm)

rowid_datatypes::=

Descriptionoftheillustrationrowid_datatypes.gif(img_text/rowid_datatypes.htm)

TheANSIsupporteddatatypesappearinthefigurethatfollows."ANSI,DB2,andSQL/DSDatatypes"
(#i54335)discussesthemappingofANSIsupporteddatatypestoOraclebuiltindatatypes.

ANSI_supported_datatypes::=

Descriptionoftheillustrationansi_supported_datatypes.gif(img_text/ansi_supported_datatypes.htm)

Oracle_supplied_types::=

Descriptionoftheillustrationoracle_supplied_types.gif(img_text/oracle_supplied_types.htm)

Foradescriptionoftheexpression_filter_type,referto"ExpressionFilterType"(#i159408).Other
Oraclesuppliedtypesfollow:

any_types::=

Descriptionoftheillustrationany_types.gif(img_text/any_types.htm)

FordescriptionsoftheAnytypes,referto"AnyTypes"(#i107578).

XML_types::=

Descriptionoftheillustrationxml_types.gif(img_text/xml_types.htm)

FordescriptionsoftheXMLtypes,referto"XMLTypes"(#i160550).

spatial_types::=

Descriptionoftheillustrationspatial_types.gif(img_text/spatial_types.htm)

Fordescriptionsofthespatialtypes,referto"SpatialTypes"(#i107588).

media_types::=

Descriptionoftheillustrationmedia_types.gif(img_text/media_types.htm)

still_image_object_types::=

Descriptionoftheillustrationstill_image_object_types.gif(img_text/still_image_object_types.htm)

Fordescriptionsofthemediatypes,referto"MediaTypes"(#i121058).

OracleBuiltinDatatypes
ThetablethatfollowssummarizesOraclebuiltindatatypes.Refertothesyntaxintheprecedingsections
forthesyntacticelements.ThecodeslistedforthedatatypesareusedinternallybyOracleDatabase.The
datatypecodeofacolumnorobjectattributeisreturnedbytheDUMPfunction.
Table21BuiltinDatatypeSummary
Code

Datatype

Description

VARCHAR2(size[BYTE|CHAR])

Variablelengthcharacterstring
havingmaximumlengthsize
bytesorcharacters.Maximum
sizeis4000bytesor
characters,andminimumis1
byteor1character.Youmust
specifysizeforVARCHAR2.
BYTEindicatesthatthecolumn

willhavebytelengthsemantics.
CHARindicatesthatthecolumn
willhavecharactersemantics.

NVARCHAR2(size)

VariablelengthUnicode
characterstringhaving
maximumlengthsize
characters.Thenumberof
bytescanbeuptotwotimes
sizeforAL16UTF16encoding
andthreetimessizeforUTF8

encoding.Maximumsizeis
determinedbythenational
charactersetdefinition,withan
upperlimitof4000bytes.You
mustspecifysizefor
NVARCHAR2.

NUMBER[(p[,s])]

Numberhavingprecisionpand
scales.Theprecisionpcan
rangefrom1to38.Thescales
canrangefrom84to127.Both
precisionandscalearein
decimaldigits.ANUMBERvalue
requiresfrom1to22bytes.

FLOAT[(p)]

AsubtypeoftheNUMBER
datatypehavingprecisionp.A
FLOATvalueisrepresented
internallyasNUMBER.The
precisionpcanrangefrom1to
126binarydigits.AFLOATvalue
requiresfrom1to22bytes.

LONG

Characterdataofvariable
lengthupto2gigabytes,or231
1bytes.Providedforbackward
compatibility.

12

DATE

ValiddaterangefromJanuary
1,4712BC,toDecember31,
9999AD.Thedefaultformatis
determinedexplicitlybythe
NLS_DATE_FORMATparameter
orimplicitlybythe
NLS_TERRITORYparameter.The
sizeisfixedat7bytes.This
datatypecontainsthedatetime
fieldsYEAR,MONTH,DAY,HOUR,
MINUTE,andSECOND.Itdoes
nothavefractionalsecondsora
timezone.

21

BINARY_FLOAT

32bitfloatingpointnumber.
Thisdatatyperequires5bytes,
includingthelengthbyte.

22

BINARY_DOUBLE

64bitfloatingpointnumber.
Thisdatatyperequires9bytes,
includingthelengthbyte.

180

TIMESTAMP

Year,month,anddayvaluesof
date,aswellashour,minute,
andsecondvaluesoftime,
where

[(fractional_seconds_preci
sion)]

fractional_seconds_precis
ionisthenumberofdigitsin

thefractionalpartoftheSECOND
datetimefield.Acceptedvalues
of
fractional_seconds_precis
ionare0to9.Thedefaultis6.

Thedefaultformatis
determinedexplicitlybythe
NLS_DATE_FORMATparameter
orimplicitlybythe
NLS_TERRITORYparameter.The
sizesvariesfrom7to11bytes,
dependingontheprecision.
Thisdatatypecontainsthe
datetimefieldsYEAR,MONTH,
DAY,HOUR,MINUTE,and
SECOND.Itcontainsfractional

secondsbutdoesnothavea
timezone.

181

TIMESTAMP

[(fractional_seconds)]WITH
TIMEZONE

AllvaluesofTIMESTAMPaswell
astimezonedisplacement
value,where
fractional_seconds_precis
ionisthenumberofdigitsin

thefractionalpartoftheSECOND
datetimefield.Acceptedvalues
are0to9.Thedefaultis6.The
defaultformatisdetermined
explicitlybythe
NLS_DATE_FORMATparameter

orimplicitlybythe
NLS_TERRITORYparameter.The
sizeisfixedat13bytes.This
datatypecontainsthedatetime
fieldsYEAR,MONTH,DAY,HOUR,
MINUTE,SECOND,
TIMEZONE_HOUR,and
TIMEZONE_MINUTE.Ithas

fractionalsecondsandan
explicittimezone.

231

TIMESTAMP

AllvaluesofTIMESTAMPWITH

[(fractional_seconds)]WITH

TIMEZONE,withthefollowing

LOCALTIMEZONE

exceptions:

Dataisnormalizedtothe
databasetimezonewhenitis
storedinthedatabase.
Whenthedataisretrieved,
usersseethedatainthe
sessiontimezone.

Thedefaultformatis
determinedexplicitlybythe
NLS_DATE_FORMATparameter
orimplicitlybythe
NLS_TERRITORYparameter.The
sizesvariesfrom7to11bytes,
dependingontheprecision.

182

INTERVALYEAR

[(year_precision)]TOMONTH

Storesaperiodoftimeinyears
andmonths,where
year_precisionisthenumber
ofdigitsintheYEARdatetime
field.Acceptedvaluesare0to
9.Thedefaultis2.Thesizeis
fixedat5bytes.

183

INTERVALDAY

[(day_precision)]TOSECOND
[(fractional_seconds)]

Storesaperiodoftimeindays,
hours,minutes,andseconds,
where

day_precisionisthe

maximumnumberofdigitsin
theDAYdatetimefield.
Acceptedvaluesare0to9.
Thedefaultis2.
fractional_seconds_prec
isionisthenumberofdigits

inthefractionalpartofthe
SECONDfield.Accepted
valuesare0to9.Thedefault
is6.

Thesizeisfixedat11bytes.

23

RAW(size)

Rawbinarydataoflengthsize
bytes.Maximumsizeis2000
bytes.Youmustspecifysize
foraRAWvalue.

24

LONGRAW

Rawbinarydataofvariable
lengthupto2gigabytes.

69

ROWID

Base64stringrepresentingthe
uniqueaddressofarowinits
table.Thisdatatypeisprimarily
forvaluesreturnedbythe
ROWIDpseudocolumn.

208

UROWID[(size)]

Base64stringrepresentingthe
logicaladdressofarowofan
indexorganizedtable.The
optionalsizeisthesizeofa
columnoftypeUROWID.The
maximumsizeanddefaultis
4000bytes.

96

CHAR[(size[BYTE|CHAR])]

Fixedlengthcharacterdataof
lengthsizebytesorcharacters.
Maximumsizeis2000bytesor

characters.Defaultand
minimumsizeis1byte.
BYTEandCHARhavethesame

semanticsasforVARCHAR2.

96

NCHAR[(size)]

Fixedlengthcharacterdataof
lengthsizecharacters.The
numberofbytescanbeupto
twotimessizeforAL16UTF16
encodingandthreetimessize
forUTF8encoding.Maximum
sizeisdeterminedbythe

nationalcharactersetdefinition,
withanupperlimitof2000
bytes.Defaultandminimum
sizeis1character.

112

CLOB

Acharacterlargeobject
containingsinglebyteor
multibytecharacters.Bothfixed
widthandvariablewidth
charactersetsaresupported,
bothusingthedatabase
characterset.Maximumsizeis
(4gigabytes1)*(database
blocksize).

112

NCLOB

Acharacterlargeobject
containingUnicodecharacters.
Bothfixedwidthandvariable
widthcharactersetsare
supported,bothusingthe
databasenationalcharacterset.
Maximumsizeis(4gigabytes
1)*(databaseblocksize).
Storesnationalcharacterset
data.

113

BLOB

Abinarylargeobject.Maximum
sizeis(4gigabytes1)*
(databaseblocksize).

114

BFILE

Containsalocatortoalarge
binaryfilestoredoutsidethe
database.Enablesbytestream
I/OaccesstoexternalLOBs
residingonthedatabaseserver.
Maximumsizeis4gigabytes.

ThesectionsthatfollowdescribetheOracledatatypesastheyarestoredinOracleDatabase.For
informationonspecifyingthesedatatypesasliterals,referto"Literals"(sql_elements003.htm#i11223).

CharacterDatatypes
Characterdatatypesstorecharacter(alphanumeric)data,whicharewordsandfreeformtext,inthe
databasecharactersetornationalcharacterset.Theyarelessrestrictivethanotherdatatypesand
consequentlyhavefewerproperties.Forexample,charactercolumnscanstoreallalphanumericvalues,
butNUMBERcolumnscanstoreonlynumericvalues.
Characterdataisstoredinstringswithbytevaluescorrespondingtooneofthecharactersets,suchas7
bitASCIIorEBCDIC,specifiedwhenthedatabasewascreated.OracleDatabasesupportsbothsingle
byteandmultibytecharactersets.
Thesedatatypesareusedforcharacterdata:

CHARDatatype(#i45647)
NCHARDatatype(#i45672)
NVARCHAR2Datatype(#i45685)
VARCHAR2Datatype(#i45694)

Forinformationonspecifyingcharacterdatatypesasliterals,referto"TextLiterals"
(sql_elements003.htm#i42617).

CHARDatatype
TheCHARdatatypespecifiesafixedlengthcharacterstring.OracleensuresthatallvaluesstoredinaCHAR
columnhavethelengthspecifiedbysize.Ifyouinsertavaluethatisshorterthanthecolumnlength,then
Oracleblankpadsthevaluetocolumnlength.Ifyoutrytoinsertavaluethatistoolongforthecolumn,
thenOraclereturnsanerror.
ThedefaultlengthforaCHARcolumnis1byteandthemaximumallowedis2000bytes.A1bytestringcan
beinsertedintoaCHAR(10)column,butthestringisblankpaddedto10bytesbeforeitisstored.

WhenyoucreateatablewithaCHARcolumn,bydefaultyousupplythecolumnlengthinbytes.TheBYTE
qualifieristhesameasthedefault.IfyouusetheCHARqualifier,forexampleCHAR(10CHAR),thenyou
supplythecolumnlengthincharacters.Acharacteristechnicallyacodepointofthedatabasecharacter
set.Itssizecanrangefrom1byteto4bytes,dependingonthedatabasecharacterset.TheBYTEand
CHARqualifiersoverridethesemanticsspecifiedbytheNLS_LENGTH_SEMANTICSparameter,whichhasa

defaultofbytesemantics.Forperformancereasons,Oraclerecommendsthatyouusethe
NLS_LENGTH_SEMANTICSparametertosetlengthsemanticsandthatyouusetheBYTEandCHARqualifiers
onlywhennecessarytooverridetheparameter.
Toensureproperdataconversionbetweendatabaseswithdifferentcharactersets,youmustensurethat
CHARdataconsistsofwellformedstrings.

SeeAlso:
OracleDatabaseGlobalizationSupportGuide(../../server.111/b28298/ch2charset.htm#NLSPG002)formore
informationoncharactersetsupportand"DatatypeComparisonRules"(sql_elements002.htm#i55214)for
informationoncomparisonsemantics

NCHARDatatype
TheNCHARdatatypeisaUnicodeonlydatatype.WhenyoucreateatablewithanNCHARcolumn,you
definethecolumnlengthincharacters.Youdefinethenationalcharactersetwhenyoucreateyour
database.
Themaximumlengthofacolumnisdeterminedbythenationalcharactersetdefinition.Width
specificationsofcharacterdatatypeNCHARrefertothenumberofcharacters.Themaximumcolumnsize
allowedis2000bytes.
Ifyouinsertavaluethatisshorterthanthecolumnlength,thenOracleblankpadsthevaluetocolumn
length.YoucannotinsertaCHARvalueintoanNCHARcolumn,norcanyouinsertanNCHARvalueintoa
CHARcolumn.

Thefollowingexamplecomparesthetranslated_descriptioncolumnofthe
pm.product_descriptionstablewithanationalcharactersetstring:
SELECTtranslated_descriptionFROMproduct_descriptionsWHEREtranslated_name=
N'LCDMonitor11/PM'

SeeAlso:
OracleDatabaseGlobalizationSupportGuide(../../server.111/b28298/ch6unicode.htm#NLSPG006)for
informationonUnicodedatatypesupport

NVARCHAR2Datatype

TheNVARCHAR2datatypeisaUnicodeonlydatatype.WhenyoucreateatablewithanNVARCHAR2column,
yousupplythemaximumnumberofcharactersitcanhold.Oraclesubsequentlystoreseachvalueinthe
columnexactlyasyouspecifyit,providedthevaluedoesnotexceedthemaximumlengthofthecolumn.
Themaximumlengthofthecolumnisdeterminedbythenationalcharactersetdefinition.Width
specificationsofcharacterdatatypeNVARCHAR2refertothenumberofcharacters.Themaximumcolumn
sizeallowedis4000bytes.

SeeAlso:
OracleDatabaseGlobalizationSupportGuide(../../server.111/b28298/ch6unicode.htm#NLSPG006)for
informationonUnicodedatatypesupport.

VARCHAR2Datatype
TheVARCHAR2datatypespecifiesavariablelengthcharacterstring.WhenyoucreateaVARCHAR2column,
yousupplythemaximumnumberofbytesorcharactersofdatathatitcanhold.Oraclesubsequently
storeseachvalueinthecolumnexactlyasyouspecifyit,providedthevaluedoesnotexceedthecolumn's
maximumlengthofthecolumn.Ifyoutrytoinsertavaluethatexceedsthespecifiedlength,thenOracle
returnsanerror.
YoumustspecifyamaximumlengthforaVARCHAR2column.Thismaximummustbeatleast1byte,
althoughtheactualstringstoredispermittedtobeazerolengthstring('').YoucanusetheCHARqualifier,
forexampleVARCHAR2(10CHAR),togivethemaximumlengthincharactersinsteadofbytes.Acharacteris
technicallyacodepointofthedatabasecharacterset.YoucanusetheBYTEqualifier,forexample
VARCHAR2(10BYTE),toexplicitlygivethemaximumlengthinbytes.Ifnoexplicitqualifierisincludedina

columnorattributedefinitionwhenadatabaseobjectwiththiscolumnorattributeiscreated,thenthe
lengthsemanticsaredeterminedbythevalueoftheNLS_LENGTH_SEMANTICSparameterofthesession
creatingtheobject.Independentlyofthemaximumlengthincharacters,thelengthofVARCHAR2data
cannotexceed4000bytes.OraclecomparesVARCHAR2valuesusingnonpaddedcomparisonsemantics.
Toensureproperdataconversionbetweendatabaseswithdifferentcharactersets,youmustensurethat
VARCHAR2dataconsistsofwellformedstrings.SeeOracleDatabaseGlobalizationSupportGuide
(../../server.111/b28298/ch2charset.htm#NLSPG002)formoreinformationoncharactersetsupport.

SeeAlso:
"DatatypeComparisonRules"(sql_elements002.htm#i55214)forinformationoncomparisonsemantics

VARCHARDatatype
DonotusetheVARCHARdatatype.UsetheVARCHAR2datatypeinstead.AlthoughtheVARCHARdatatypeis
currentlysynonymouswithVARCHAR2,theVARCHARdatatypeisscheduledtoberedefinedasaseparate
datatypeusedforvariablelengthcharacterstringscomparedwithdifferentcomparisonsemantics.

NumericDatatypes

TheOracleDatabasenumericdatatypesstorepositiveandnegativefixedandfloatingpointnumbers,
zero,infinity,andvaluesthataretheundefinedresultofanoperation"notanumber"orNAN.For
informationonspecifyingnumericdatatypesasliterals,referto"NumericLiterals"
(sql_elements003.htm#i139891).

NUMBERDatatype
TheNUMBERdatatypestoreszeroaswellaspositiveandnegativefixednumberswithabsolutevaluesfrom
1.0x10130tobutnotincluding1.0x10126.Ifyouspecifyanarithmeticexpressionwhosevaluehasan
absolutevaluegreaterthanorequalto1.0x10126,thenOraclereturnsanerror.EachNUMBERvalue
requiresfrom1to22bytes.
Specifyafixedpointnumberusingthefollowingform:
NUMBER(p,s)

where:

pistheprecision,orthemaximumnumberofsignificantdecimaldigits,wherethemostsignificantdigit

istheleftmostnonzerodigit,andtheleastsignificantdigitistherightmostknowndigit.Oracle
guaranteestheportabilityofnumberswithprecisionofupto20base100digits,whichisequivalentto
39or40decimaldigitsdependingonthepositionofthedecimalpoint.
sisthescale,orthenumberofdigitsfromthedecimalpointtotheleastsignificantdigit.Thescalecan

rangefrom84to127.

Positivescaleisthenumberofsignificantdigitstotherightofthedecimalpointtoandincludingthe
leastsignificantdigit.
Negativescaleisthenumberofsignificantdigitstotheleftofthedecimalpoint,tobutnotincluding
theleastsignificantdigit.Fornegativescaletheleastsignificantdigitisontheleftsideofthedecimal
point,becausetheactualdataisroundedtothespecifiednumberofplacestotheleftofthedecimal
point.Forexample,aspecificationof(10,2)meanstoroundtohundreds.

Scalecanbegreaterthanprecision,mostcommonlywhenenotationisused.Whenscaleisgreaterthan
precision,theprecisionspecifiesthemaximumnumberofsignificantdigitstotherightofthedecimalpoint.
Forexample,acolumndefinedasNUMBER(4,5)requiresazeroforthefirstdigitafterthedecimalpoint
androundsallvaluespastthefifthdigitafterthedecimalpoint.
Itisgoodpracticetospecifythescaleandprecisionofafixedpointnumbercolumnforextraintegrity
checkingoninput.Specifyingscaleandprecisiondoesnotforceallvaluestoafixedlength.Ifavalue
exceedstheprecision,thenOraclereturnsanerror.Ifavalueexceedsthescale,thenOracleroundsit.
Specifyanintegerusingthefollowingform:

NUMBER(p)

Thisrepresentsafixedpointnumberwithprecisionpandscale0andisequivalenttoNUMBER(p,0).
Specifyafloatingpointnumberusingthefollowingform:
NUMBER

TheabsenceofprecisionandscaledesignatorsspecifiesthemaximumrangeandprecisionforanOracle
number.

SeeAlso:
"FloatingPointNumbers"(#i140176)
Table22(#g196646)showhowOraclestoresdatausingdifferentprecisionsandscales.
Table22StorageofScaleandPrecision
ActualData

SpecifiedAs

StoredAs

123.89

NUMBER

123.89

123.89

NUMBER(3)

124

123.89

NUMBER(3,2)

exceedsprecision

123.89

NUMBER(4,2)

exceedsprecision

123.89

NUMBER(5,2)

123.89

123.89

NUMBER(6,1)

123.9

123.89

NUMBER(6,2)

100

.01234

NUMBER(4,5)

.01234

.00012

NUMBER(4,5)

.00012

.000127

NUMBER(4,5)

.00013

.0000012

NUMBER(2,7)

.0000012

.00000123

NUMBER(2,7)

.0000012

1.2e4

NUMBER(2,5)

0.00012

1.2e5

NUMBER(2,5)

0.00001

FLOATDatatype
TheFLOATdatatypeisasubtypeofNUMBER.Itcanbespecifiedwithorwithoutprecision,whichhasthe
samedefinitionithasforNUMBERandcanrangefrom1to126.Scalecannotbespecified,butisinterpreted
fromthedata.EachFLOATvaluerequiresfrom1to22bytes.
Toconvertfrombinarytodecimalprecision,multiplynby0.30103.Toconvertfromdecimaltobinary
precision,multiplythedecimalprecisionby3.32193.Themaximumof126digitsofbinaryprecisionis
roughlyequivalentto38digitsofdecimalprecision.
ThedifferencebetweenNUMBERandFLOATisbestillustratedbyexample.Inthefollowingexamplethe
samevaluesareinsertedintoNUMBERandFLOATcolumns:
CREATETABLEtest(col1NUMBER(5,2),col2FLOAT(5))INSERTINTOtestVALUES
(1.23,1.23)INSERTINTOtestVALUES(7.89,7.89)INSERTINTOtestVALUES
(12.79,12.79)INSERTINTOtestVALUES(123.45,123.45)SELECT*FROMtest
COL1COL21.231.27.897.912.7913123.45120

Inthisexample,theFLOATvaluereturnedcannotexceed5binarydigits.Thelargestdecimalnumberthat
canberepresentedby5binarydigitsis31.Thelastrowcontainsdecimalvaluesthatexceed31.
Therefore,theFLOATvaluemustbetruncatedsothatitssignificantdigitsdonotrequiremorethan5binary
digits.Thus123.45isroundedto120,whichhasonlytwosignificantdecimaldigits,requiringonly4binary
digits.
OracleDatabaseusestheOracleFLOATdatatypeinternallywhenconvertingANSIFLOATdata.Oracle
FLOATisavailableforyoutouse,butOraclerecommendsthatyouusetheBINARY_FLOATand
BINARY_DOUBLEdatatypesinstead,astheyaremorerobust.Referto"FloatingPointNumbers"(#i140176)

formoreinformation.

FloatingPointNumbers
Floatingpointnumberscanhaveadecimalpointanywherefromthefirsttothelastdigitorcanhaveno
decimalpointatall.Anexponentmayoptionallybeusedfollowingthenumbertoincreasetherange,for
example,1.777e20.Ascalevalueisnotapplicabletofloatingpointnumbers,becausethenumberofdigits
thatcanappearafterthedecimalpointisnotrestricted.
BinaryfloatingpointnumbersdifferfromNUMBERinthewaythevaluesarestoredinternallybyOracle
Database.ValuesarestoredusingdecimalprecisionforNUMBER.Allliteralsthatarewithintherangeand
precisionsupportedbyNUMBERarestoredexactlyasNUMBER.Literalsarestoredexactlybecauseliterals
areexpressedusingdecimalprecision(thedigits0through9).Binaryfloatingpointnumbersarestored
usingbinaryprecision(thedigits0and1).Suchastorageschemecannotrepresentallvaluesusing
decimalprecisionexactly.Frequently,theerrorthatoccurswhenconvertingavaluefromdecimaltobinary
precisionisundonewhenthevalueisconvertedbackfrombinarytodecimalprecision.Theliteral0.1is
suchanexample.
OracleDatabaseprovidestwonumericdatatypesexclusivelyforfloatingpointnumbers:

BINARY_FLOAT
BINARY_FLOATisa32bit,singleprecisionfloatingpointnumberdatatype.EachBINARY_FLOATvalue

requires5bytes,includingalengthbyte.

BINARY_DOUBLE
BINARY_DOUBLEisa64bit,doubleprecisionfloatingpointnumberdatatype.EachBINARY_DOUBLEvalue

requires9bytes,includingalengthbyte.
InaNUMBERcolumn,floatingpointnumbershavedecimalprecision.InaBINARY_FLOATor
BINARY_DOUBLEcolumn,floatingpointnumbershavebinaryprecision.Thebinaryfloatingpointnumbers

supportthespecialvaluesinfinityandNaN(notanumber).
YoucanspecifyfloatingpointnumberswithinthelimitslistedinTable23(#g195556).Theformatfor
specifyingfloatingpointnumbersisdefinedin"NumericLiterals"(sql_elements003.htm#i139891).
Table23FloatingPointNumberLimits
Value

BINARY_FLOAT

BINARY_DOUBLE

Maximumpositivefinitevalue

3.40282E+38F

1.79769313486231E+308

Minimumpositivefinitevalue

1.17549E38F

2.22507485850720E308

IEEE754Conformance

TheOracleimplementationoffloatingpointdatatypesconformssubstantiallywiththeInstituteofElectrical
andElectronicsEngineers(IEEE)StandardforBinaryFloatingPointArithmetic,IEEEStandard7541985
(IEEE754).ThefloatingpointdatatypesconformtoIEEE754inthefollowingareas:

TheSQLfunctionSQRTimplementssquareroot.SeeSQRT(functions156.htm#i1009289).
TheSQLfunctionREMAINDERimplementsremainder.SeeREMAINDER(functions140.htm#i1300767).
Arithmeticoperatorsconform.See"ArithmeticOperators"(operators002.htm#i1028549).
Comparisonoperatorsconform,exceptforcomparisonswithNaN.OracleordersNaNgreatestwith
respecttoallothervalues,andevaluatesNaNequaltoNaN.See"FloatingPointConditions"
(conditions003.htm#i1052323).
Conversionoperatorsconform.See"ConversionFunctions"(functions001.htm#i88892).
Thedefaultroundingmodeissupported.
Thedefaultexceptionhandlingmodeissupported.
ThespecialvaluesINF,INF,andNaNaresupported.See"FloatingPointConditions"
(conditions003.htm#i1052323).

RoundingofBINARY_FLOATandBINARY_DOUBLEvaluestointegervaluedBINARY_FLOATand
BINARY_DOUBLEvaluesisprovidedbytheSQLfunctionsROUND,TRUNC,CEIL,andFLOOR.

RoundingofBINARY_FLOAT/BINARY_DOUBLEtodecimalanddecimaltoBINARY_FLOAT/BINARY_DOUBLE
isprovidedbytheSQLfunctionsTO_CHAR,TO_NUMBER,TO_NCHAR,TO_BINARY_FLOAT,
TO_BINARY_DOUBLE,andCAST.

ThefloatingpointdatatypesdonotconformtoIEEE754inthefollowingareas:

0iscoercedto+0.
ComparisonwithNaNisnotsupported.
AllNaNvaluesarecoercedtoeitherBINARY_FLOAT_NANorBINARY_DOUBLE_NAN.
Nondefaultroundingmodesarenotsupported.
Nondefaultexceptionhandlingmodearenotsupported.

NumericPrecedence

Numericprecedencedetermines,foroperationsthatsupportnumericdatatypes,thedatatypeOracle
usesiftheargumentstotheoperationhavedifferentdatatypes.BINARY_DOUBLEhasthehighestnumeric
precedence,followedbyBINARY_FLOAT,andfinallybyNUMBER.Therefore,inanyoperationonmultiple
numericvalues:

IfanyoftheoperandsisBINARY_DOUBLE,thenOracleattemptstoconvertalltheoperandsimplicitlyto
BINARY_DOUBLEbeforeperformingtheoperation.

IfnoneoftheoperandsisBINARY_DOUBLEbutanyoftheoperandsisBINARY_FLOAT,thenOracle
attemptstoconvertalltheoperandsimplicitlytoBINARY_FLOATbeforeperformingtheoperation.
Otherwise,OracleattemptstoconvertalltheoperandstoNUMBERbeforeperformingtheoperation.

Ifanyimplicitconversionisneededandfails,thentheoperationfails.RefertoTable210,"ImplicitType
ConversionMatrix"(sql_elements002.htm#g195937)formoreinformationonimplicitconversion.
Inthecontextofotherdatatypes,numericdatatypeshavelowerprecedencethanthedatetime/interval
datatypesandhigherprecedencethancharacterandallotherdatatypes.

LONGDatatype
DonotcreatetableswithLONGcolumns.UseLOBcolumns(CLOB,NCLOB,BLOB)instead.LONGcolumns
aresupportedonlyforbackwardcompatibility.
LONGcolumnsstorevariablelengthcharacterstringscontainingupto2gigabytes1,or2311bytes.LONG

columnshavemanyofthecharacteristicsofVARCHAR2columns.YoucanuseLONGcolumnstostorelong
textstrings.ThelengthofLONGvaluesmaybelimitedbythememoryavailableonyourcomputer.LONG
literalsareformedasdescribedfor"TextLiterals"(sql_elements003.htm#i42617).
OraclealsorecommendsthatyouconvertexistingLONGcolumnstoLOBcolumns.LOBcolumnsare
subjecttofarfewerrestrictionsthanLONGcolumns.Further,LOBfunctionalityisenhancedinevery
release,whereasLONGfunctionalityhasbeenstaticforseveralreleases.Seethe
modify_col_propertiesclauseofALTERTABLE(statements_3001.htm#CJAHHIBI)andTO_LOB
(functions193.htm#i79464)formoreinformationonconvertingLONGcolumnstoLOB.

YoucanreferenceLONGcolumnsinSQLstatementsintheseplaces:

SELECTlists
SETclausesofUPDATEstatements
VALUESclausesofINSERTstatements

TheuseofLONGvaluesissubjecttotheserestrictions:

AtablecancontainonlyoneLONGcolumn.
YoucannotcreateanobjecttypewithaLONGattribute.
LONGcolumnscannotappearinWHEREclausesorinintegrityconstraints(exceptthattheycanappearin
NULLandNOTNULLconstraints).
LONGcolumnscannotbeindexed.
LONGdatacannotbespecifiedinregularexpressions.

AstoredfunctioncannotreturnaLONGvalue.
YoucandeclareavariableorargumentofaPL/SQLprogramunitusingtheLONGdatatype.However,
youcannotthencalltheprogramunitfromSQL.
WithinasingleSQLstatement,allLONGcolumns,updatedtables,andlockedtablesmustbelocatedon
thesamedatabase.
LONGandLONGRAWcolumnscannotbeusedindistributedSQLstatementsandcannotbereplicated.

IfatablehasbothLONGandLOBcolumns,thenyoucannotbindmorethan4000bytesofdatatoboth
theLONGandLOBcolumnsinthesameSQLstatement.However,youcanbindmorethan4000bytesof
datatoeithertheLONGortheLOBcolumn.

Inaddition,LONGcolumnscannotappearinthesepartsofSQLstatements:

GROUPBYclauses,ORDERBYclauses,orCONNECTBYclausesorwiththeDISTINCToperatorinSELECT

statements
TheUNIQUEoperatorofaSELECTstatement
ThecolumnlistofaCREATECLUSTERstatement
TheCLUSTERclauseofaCREATEMATERIALIZEDVIEWstatement
SQLbuiltinfunctions,expressions,orconditions
SELECTlistsofqueriescontainingGROUPBYclauses

SELECTlistsofsubqueriesorqueriescombinedbytheUNION,INTERSECT,orMINUSsetoperators
SELECTlistsofCREATETABLE...ASSELECTstatements
ALTERTABLE...MOVEstatements
SELECTlistsinsubqueriesinINSERTstatements

TriggerscanusetheLONGdatatypeinthefollowingmanner:

ASQLstatementwithinatriggercaninsertdataintoaLONGcolumn.
IfdatafromaLONGcolumncanbeconvertedtoaconstraineddatatype(suchasCHARandVARCHAR2),
thenaLONGcolumncanbereferencedinaSQLstatementwithinatrigger.
VariablesintriggerscannotbedeclaredusingtheLONGdatatype.
:NEWand:OLDcannotbeusedwithLONGcolumns.

YoucanuseOracleCallInterfacefunctionstoretrieveaportionofaLONGvaluefromthedatabase.

SeeAlso:
OracleCallInterfaceProgrammer'sGuide(http://www.oracle.com/pls/topic/lookup?ctx=db111&id=LNOCI030)

DatetimeandIntervalDatatypes
ThedatetimedatatypesareDATE,TIMESTAMP,TIMESTAMPWITHTIMEZONE,andTIMESTAMPWITHLOCAL
TIMEZONE.Valuesofdatetimedatatypesaresometimescalleddatetimes.Theintervaldatatypesare
INTERVALYEARTOMONTHandINTERVALDAYTOSECOND.Valuesofintervaldatatypesaresometimes

calledintervals.Forinformationonexpressingdatetimeandintervalvaluesasliterals,referto"Datetime
Literals"(sql_elements003.htm#BABGIGCJ)and"IntervalLiterals"(sql_elements003.htm#i38598).
Bothdatetimesandintervalsaremadeupoffields.Thevaluesofthesefieldsdeterminethevalueofthe
datatype.Table24(#BABFDAEI)liststhedatetimefieldsandtheirpossiblevaluesfordatetimesand
intervals.
ToavoidunexpectedresultsinyourDMLoperationsondatetimedata,youcanverifythedatabaseand
sessiontimezonesbyqueryingthebuiltinSQLfunctionsDBTIMEZONEandSESSIONTIMEZONE.Ifthetime
zoneshavenotbeensetmanually,thenOracleDatabaseusestheoperatingsystemtimezonebydefault.
IftheoperatingsystemtimezoneisnotavalidOracletimezone,thenOracleusesUTCasthedefault
value.

Table24DatetimeFieldsandValues
DatetimeField

ValidValuesforDatetime

ValidValuesforINTERVAL

YEAR

4712to9999(excludingyear
0)

Anypositiveornegativeinteger

MONTH

01to12

0to11

DAY

01to31(limitedbythevalues
ofMONTHandYEAR,accordingto

Anypositiveornegativeinteger

therulesofthecurrentNLS
calendarparameter)

HOUR

00to23

0to23

MINUTE

00to59

0to59

SECOND

00to59.9(n),where9(n)isthe
precisionoftimefractional
seconds.The9(n)portionisnot
applicableforDATE.

0to59.9(n),where9(n)isthe
precisionofintervalfractional
seconds

TIMEZONE_HOUR

12to14(Thisrange
accommodatesdaylightsaving
timechanges.)Notapplicable
forDATEorTIMESTAMP.

Notapplicable

TIMEZONE_MINUTE

00to59.Notapplicablefor
DATEorTIMESTAMP.

Notapplicable

QuerytheTZNAMEcolumnofthe
V$TIMEZONE_NAMESdata

Notapplicable

(Seenoteatendoftable)

TIMEZONE_REGION

dictionaryview.Notapplicable
forDATEorTIMESTAMP.Fora
completelistingofalltimezone
regions,refertoOracle
DatabaseGlobalizationSupport
Guide

(../../server.111/b28298/ch4datetime.htm
#NLSPG004).

TIMEZONE_ABBR

QuerytheTZABBREVcolumnof

Notapplicable

theV$TIMEZONE_NAMESdata
dictionaryview.Notapplicable
forDATEorTIMESTAMP.

Note:
TIMEZONE_HOURandTIMEZONE_MINUTEarespecifiedtogetherandinterpretedasanentityin

theformat+|hh:mm,withvaluesrangingfrom12:59to+14:00.RefertoOracleData
Providerfor.NETDeveloper'sGuide(../../win.111/b28375/OracleTimeStampStructure.htm#ODPNT0002)for
informationonspecifyingtimezonevaluesforthatAPI.

DATEDatatype
TheDATEdatatypestoresdateandtimeinformation.Althoughdateandtimeinformationcanbe
representedinbothcharacterandnumberdatatypes,theDATEdatatypehasspecialassociatedproperties.
ForeachDATEvalue,Oraclestoresthefollowinginformation:century,year,month,date,hour,minute,and
second.
YoucanspecifyaDATEvalueasaliteral,oryoucanconvertacharacterornumericvaluetoadatevalue
withtheTO_DATEfunction.ForexamplesofexpressingDATEvaluesinboththeseways,referto"Datetime
Literals"(sql_elements003.htm#BABGIGCJ).

UsingJulianDays
AJuliandaynumberisthenumberofdayssinceJanuary1,4712BC.Juliandaysallowcontinuousdating
fromacommonreference.Youcanusethedateformatmodel"J"withdatefunctionsTO_DATEand
TO_CHARtoconvertbetweenOracleDATEvaluesandtheirJulianequivalents.

Note:
OracleDatabaseusestheastronomicalsystemofcalculatingJuliandays,inwhichtheyear
4713BCisspecifiedas4712.ThehistoricalsystemofcalculatingJuliandays,incontrast,
specifies4713BCas4713.IfyouarecomparingOracleJuliandayswithvaluescalculated
usingthehistoricalsystem,thentakecaretoallowforthe365daydifferenceinBCdates.For
moreinformation,seehttp://aa.usno.navy.mil/faq/docs/millennium.php
(http://aa.usno.navy.mil/faq/docs/millennium.php).

Thedefaultdatevaluesaredeterminedasfollows:

Theyearisthecurrentyear,asreturnedbySYSDATE.
Themonthisthecurrentmonth,asreturnedbySYSDATE.
Thedayis01(thefirstdayofthemonth).
Thehour,minute,andsecondareall0.

Thesedefaultvaluesareusedinaquerythatrequestsdatevalueswherethedateitselfisnotspecified,as
inthefollowingexample,whichisissuedinthemonthofMay:
SELECTTO_DATE('2005','YYYY')FROMDUALTO_DATE('01MAY05

Example
ThisstatementreturnstheJulianequivalentofJanuary1,1997:
SELECTTO_CHAR(TO_DATE('01011997','MMDDYYYY'),'J')FROMDUALTO_CHAR
2450450

SeeAlso:
"SelectingfromtheDUALTable"(queries009.htm#i2054159)foradescriptionoftheDUALtable

TIMESTAMPDatatype
TheTIMESTAMPdatatypeisanextensionoftheDATEdatatype.Itstorestheyear,month,anddayofthe
DATEdatatype,plushour,minute,andsecondvalues.Thisdatatypeisusefulforstoringprecisetime

values.SpecifytheTIMESTAMPdatatypeasfollows:
TIMESTAMP[(fractional_seconds_precision)]

wherefractional_seconds_precisionoptionallyspecifiesthenumberofdigitsOraclestoresinthe
fractionalpartoftheSECONDdatetimefield.Whenyoucreateacolumnofthisdatatype,thevaluecanbea
numberintherange0to9.Thedefaultis6.

SeeAlso:
TO_TIMESTAMP(functions201.htm#i999843)forinformationonconvertingcharacterdatatoTIMESTAMP
data

TIMESTAMPWITHTIMEZONEDatatype
TIMESTAMPWITHTIMEZONEisavariantofTIMESTAMPthatincludesatimezoneregionnameoraatime

zoneoffsetinitsvalue.Thetimezoneoffsetisthedifference(inhoursandminutes)betweenlocaltime
andUTC(CoordinatedUniversalTimeformerlyGreenwichMeanTime).Thisdatatypeisusefulfor
collectingandevaluatingdateinformationacrossgeographicregions.

SpecifytheTIMESTAMPWITHTIMEZONEdatatypeasfollows:
TIMESTAMP[(fractional_seconds_precision)]WITHTIMEZONE

wherefractional_seconds_precisionoptionallyspecifiesthenumberofdigitsOraclestoresinthe
fractionalpartoftheSECONDdatetimefield.Whenyoucreateacolumnofthisdatatype,thevaluecanbea
numberintherange0to9.Thedefaultis6.
Oracletimezonedataisderivedfromthepublicdomaininformationavailableat
ftp://elsie.nci.nih.gov/pub/
(ftp://elsie.nci.nih.gov/pub/).Oracletimezonedatamaynot
reflectthemostrecentdataavailableatthissite.

SeeAlso:
OracleDatabaseGlobalizationSupportGuide(../../server.111/b28298/ch4datetime.htm#NLSPG004)formore
informationonOracletimezonedata
"SupportforDaylightSavingTimes"(#i51607)andTable217,"MatchingCharacterDataandFormat
ModelswiththeFXFormatModelModifier"(sql_elements004.htm#g195443)forinformationondaylight
savingsupport
TO_TIMESTAMP_TZ(functions202.htm#i999847)forinformationonconvertingcharacterdatato
TIMESTAMPWITHTIMEZONEdata
ALTERSESSION(statements_2012.htm#i2231814)forinformationontheERROR_ON_OVERLAP_TIME
sessionparameter

TIMESTAMPWITHLOCALTIMEZONEDatatype
TIMESTAMPWITHLOCALTIMEZONEisanothervariantofTIMESTAMPthatincludesatimezoneoffsetinits

value.ItdiffersfromTIMESTAMPWITHTIMEZONEinthatdatastoredinthedatabaseisnormalizedtothe
databasetimezone,andthetimezoneoffsetisnotstoredaspartofthecolumndata.Whenauser
retrievesthedata,Oraclereturnsitintheuser'slocalsessiontimezone.Thetimezoneoffsetisthe
difference(inhoursandminutes)betweenlocaltimeandUTC(CoordinatedUniversalTimeformerly
GreenwichMeanTime).Thisdatatypeisusefulfordisplayingdateinformationinthetimezoneoftheclient
systeminatwotierapplication.
SpecifytheTIMESTAMPWITHLOCALTIMEZONEdatatypeasfollows:
TIMESTAMP[(fractional_seconds_precision)]WITHLOCALTIMEZONE

wherefractional_seconds_precisionoptionallyspecifiesthenumberofdigitsOraclestoresinthe
fractionalpartoftheSECONDdatetimefield.Whenyoucreateacolumnofthisdatatype,thevaluecanbea
numberintherange0to9.Thedefaultis6.

Oracletimezonedataisderivedfromthepublicdomaininformationavailableat
ftp://elsie.nci.nih.gov/pub/
(ftp://elsie.nci.nih.gov/pub/).Oracletimezonedatamaynot
reflectthemostrecentdataavailableatthissite.

SeeAlso:
OracleDatabaseGlobalizationSupportGuide(../../server.111/b28298/ch12scanner.htm#NLSPG012)formore
informationonOracletimezonedata
OracleDatabaseAdvancedApplicationDeveloper'sGuide
(../../appdev.111/b28424/adfns_sqltypes.htm#ADFNS00304)forexamplesofusingthisdatatypeandCAST
(functions016.htm#i1269136)forinformationonconvertingcharacterdatatoTIMESTAMPWITHLOCALTIME
ZONE

INTERVALYEARTOMONTHDatatype
INTERVALYEARTOMONTHstoresaperiodoftimeusingtheYEARandMONTHdatetimefields.Thisdatatype

isusefulforrepresentingthedifferencebetweentwodatetimevalueswhenonlytheyearandmonthvalues
aresignificant.
SpecifyINTERVALYEARTOMONTHasfollows:
INTERVALYEAR[(year_precision)]TOMONTH

whereyear_precisionisthenumberofdigitsintheYEARdatetimefield.Thedefaultvalueof
year_precisionis2.
Youhaveagreatdealofflexibilitywhenspecifyingintervalvaluesasliterals.Referto"IntervalLiterals"
(sql_elements003.htm#i38598)fordetailedinformationonspecifyingintervalvaluesasliterals.Alsosee
"DatetimeandIntervalExamples"(#BABBICGH)foranexampleusingintervals.

INTERVALDAYTOSECONDDatatype
INTERVALDAYTOSECONDstoresaperiodoftimeintermsofdays,hours,minutes,andseconds.This

datatypeisusefulforrepresentingtheprecisedifferencebetweentwodatetimevalues.
Specifythisdatatypeasfollows:
INTERVALDAY[(day_precision)]TOSECOND[(fractional_seconds_precision)]

where

day_precisionisthenumberofdigitsintheDAYdatetimefield.Acceptedvaluesare0to9.Thedefault

is2.
fractional_seconds_precisionisthenumberofdigitsinthefractionalpartoftheSECONDdatetime

field.Acceptedvaluesare0to9.Thedefaultis6.

Youhaveagreatdealofflexibilitywhenspecifyingintervalvaluesasliterals.Referto"IntervalLiterals"
(sql_elements003.htm#i38598)fordetailedinformationonspecifyintervalvaluesasliterals.Alsosee"Datetime
andIntervalExamples"(#BABBICGH)foranexampleusingintervals.

Datetime/IntervalArithmetic
Youcanperformanumberofarithmeticoperationsondate(DATE),timestamp(TIMESTAMP,TIMESTAMP
WITHTIMEZONE,andTIMESTAMPWITHLOCALTIMEZONE)andinterval(INTERVALDAYTOSECONDand
INTERVALYEARTOMONTH)data.Oraclecalculatestheresultsbasedonthefollowingrules:

YoucanuseNUMBERconstantsinarithmeticoperationsondateandtimestampvalues,butnotinterval
values.OracleinternallyconvertstimestampvaluestodatevaluesandinterpretsNUMBERconstantsin
arithmeticdatetimeandintervalexpressionsasnumbersofdays.Forexample,SYSDATE+1is
tomorrow.SYSDATE7isoneweekago.SYSDATE+(10/1440)istenminutesfromnow.Subtractingthe
hire_datecolumnofthesampletableemployeesfromSYSDATEreturnsthenumberofdayssince

eachemployeewashired.Youcannotmultiplyordividedateortimestampvalues.
OracleimplicitlyconvertsBINARY_FLOATandBINARY_DOUBLEoperandstoNUMBER.
EachDATEvaluecontainsatimecomponent,andtheresultofmanydateoperationsincludeafraction.
Thisfractionmeansaportionofoneday.Forexample,1.5daysis36hours.Thesefractionsarealso
returnedbyOraclebuiltinfunctionsforcommonoperationsonDATEdata.Forexample,the
MONTHS_BETWEENfunctionreturnsthenumberofmonthsbetweentwodates.Thefractionalportionof

theresultrepresentsthatportionofa31daymonth.
IfoneoperandisaDATEvalueoranumericvalue,neitherofwhichcontainstimezoneorfractional
secondscomponents,then:

OracleimplicitlyconvertstheotheroperandtoDATEdata.Theexceptionismultiplicationofanumeric
valuetimesaninterval,whichreturnsaninterval.
Iftheotheroperandhasatimezonevalue,thenOracleusesthesessiontimezoneinthereturned
value.
Iftheotheroperandhasafractionalsecondsvalue,thenthefractionalsecondsvalueislost.

Whenyoupassatimestamp,interval,ornumericvaluetoabuiltinfunctionthatwasdesignedonlyfor
theDATEdatatype,OracleimplicitlyconvertsthenonDATEvaluetoaDATEvalue.Referto"Datetime
Functions"(functions001.htm#i88891)forinformationonwhichfunctionscauseimplicitconversiontoDATE.
Whenintervalcalculationsreturnadatetimevalue,theresultmustbeanactualdatetimevalueorthe
databasereturnsanerror.Forexample,thenexttwostatementsreturnerrors:
SELECTTO_DATE('31AUG2004','DDMONYYYY')+TO_YMINTERVAL('01')FROMDUAL
SELECTTO_DATE('29FEB2004','DDMONYYYY')+TO_YMINTERVAL('10')FROMDUAL

Thefirstfailsbecauseaddingonemonthtoa31daymonthwouldresultinSeptember31,whichisnota
validdate.Thesecondfailsbecauseaddingoneyeartoadatethatexistsonlyeveryfouryearsisnot
valid.However,thenextstatementsucceeds,becauseaddingfouryearstoaFebruary29dateisvalid:
SELECTTO_DATE('29FEB2004','DDMONYYYY')+TO_YMINTERVAL('40')FROMDUAL
TO_DATE('29FEB08

OracleperformsalltimestamparithmeticinUTCtime.ForTIMESTAMPWITHLOCALTIMEZONE,Oracle
convertsthedatetimevaluefromthedatabasetimezonetoUTCandconvertsbacktothedatabase
timezoneafterperformingthearithmetic.ForTIMESTAMPWITHTIMEZONE,thedatetimevalueisalways
inUTC,sonoconversionisnecessary.

Table25(#g196492)isamatrixofdatetimearithmeticoperations.Dashesrepresentoperationsthatarenot
supported.
Table25MatrixofDatetimeArithmetic
Operand&
Operator

DATE

TIMESTAMP

INTERVAL

Numeric

DATE

DATE

DATE

NUMBER

INTERVAL

DATE

DATE

TIMESTAMP

TIMESTAMP

DATE

INTERVAL

INTERVAL

TIMESTAMP

DATE

INTERVAL

DATE

TIMESTAMP

INTERVAL

INTERVAL

INTERVAL

INTERVAL

Numeric

DATE

DATE

NA

NA

INTERVAL

NA

NA

Examples

Youcanaddanintervalvalueexpressiontoastarttime.Considerthesampletableoe.orderswitha
columnorder_date.Thefollowingstatementadds30daystothevalueoftheorder_datecolumn:
SELECTorder_id,order_date+INTERVAL'30'DAYFROMordersORDERBYorder_id,
"DueDate"

SupportforDaylightSavingTimes
OracleDatabaseautomaticallydetermines,foranygiventimezoneregion,whetherdaylightsavingisin
effectandreturnslocaltimevaluesaccordingly.ThedatetimevalueissufficientforOracletodetermine
whetherdaylightsavingtimeisineffectforagivenregioninallcasesexceptboundarycases.Aboundary
caseoccursduringtheperiodwhendaylightsavinggoesintoorcomesoutofeffect.Forexample,inthe
USPacificregion,whendaylightsavinggoesintoeffect,thetimechangesfrom2:00a.m.to3:00a.m.The
onehourintervalbetween2and3a.m.doesnotexist.Whendaylightsavinggoesoutofeffect,thetime
changesfrom2:00a.m.backto1:00a.m.,andtheonehourintervalbetween1and2a.m.isrepeated.
Toresolvetheseboundarycases,OracleusestheTZRandTZDformatelements,asdescribedinTable2
17(sql_elements004.htm#g195443).TZRrepresentsthetimezoneregionindatetimeinputstrings.Examples
are'Australia/North','UTC',and'Singapore'.TZDrepresentsanabbreviatedformofthetimezone
regionwithdaylightsavinginformation.Examplesare'PST'forUS/Pacificstandardtimeand'PDT'for
US/Pacificdaylighttime.ToseealistingofvalidvaluesfortheTZRandTZDformatelements,querythe
TZNAMEandTZABBREVcolumnsoftheV$TIMEZONE_NAMESdynamicperformanceview.

Note:
Timezoneregionnamesareneededbythedaylightsavingfeature.Theregionnamesare
storedintwotimezonefiles.Thedefaulttimezonefileisasmallfilecontainingonlythemost
commontimezonestomaximizeperformance.Ifyourtimezoneisnotinthedefaultfile,then
youwillnothavedaylightsavingsupportuntilyouprovideapathtothecomplete(larger)file
bywayoftheORA_TZFILEenvironmentvariable.
Foracompletelistingofthetimezoneregionnamesinbothfiles,refertoOracleDatabaseGlobalization
SupportGuide(../../server.111/b28298/toc.htm).
Oracletimezonedataisderivedfromthepublicdomaininformationavailableat
ftp://elsie.nci.nih.gov/pub/
(ftp://elsie.nci.nih.gov/pub/).Oracletimezonedatamaynot
reflectthemostrecentdataavailableatthissite.

SeeAlso:
"DatetimeFormatModels"(sql_elements004.htm#i34924)forinformationontheformatelementsandthe
sessionparameterERROR_ON_OVERLAP_TIME(statements_2012.htm#i2252050).
OracleDatabaseGlobalizationSupportGuide(../../server.111/b28298/ch4datetime.htm#NLSPG004)formore
informationonOracletimezonedata

OracleDatabaseReference(../../server.111/b28320/dynviews_3105.htm#REFRN30290)forinformationonthe
dynamicperformanceviews

DatetimeandIntervalExamples
Thefollowingexampleshowshowtospecifysomedatetimeandintervaldatatypes.
CREATETABLEtime_table(start_timeTIMESTAMP,duration_1INTERVALDAY(6)TO
SECOND(5),duration_2INTERVALYEARTOMONTH)

Thestart_timecolumnisoftypeTIMESTAMP.TheimplicitfractionalsecondsprecisionofTIMESTAMPis
6.
Theduration_1columnisoftypeINTERVALDAYTOSECOND.ThemaximumnumberofdigitsinfieldDAY
is6andthemaximumnumberofdigitsinthefractionalsecondis5.Themaximumnumberofdigitsinall
otherdatetimefieldsis2.
Theduration_2columnisoftypeINTERVALYEARTOMONTH.Themaximumnumberofdigitsofthevalue
ineachfield(YEARandMONTH)is2.
Intervaldatatypesdonothaveformatmodels.Therefore,toadjusttheirpresentation,youmustcombine
characterfunctionssuchasEXTRACTandconcatenatethecomponents.Forexample,thefollowing
examplesquerythehr.employeesandoe.orderstables,respectively,andchangeintervaloutputfrom
theform"yymm"to"yyyearsmmmonths"andfrom"ddhh"to"dddddayshhhours":
SELECTlast_name,EXTRACT(YEARFROM(SYSDATEhire_date)YEARTOMONTH)||'
years'||EXTRACT(MONTHFROM(SYSDATEhire_date)YEARTOMONTH)||'months'
"Interval"FROMemployeesLAST_NAMEInterval
King17years11monthsKochhar15years8monthsDeHaan12years4
monthsHunold15years4monthsErnst14years0monthsAustin7years11months
Pataballa7years3monthsLorentz6years3monthsGreenberg10years9months.
..SELECTorder_id,EXTRACT(DAYFROM(SYSDATEorder_date)DAYTOSECOND)||'
days'||EXTRACT(HOURFROM(SYSDATEorder_date)DAYTOSECOND)||'hours'
"Interval"FROMordersORDER_IDInterval2458
2095days18hours23972000days17hours24542048days16hours23541762days
16hours23581950days15hours23811823days13hours24402080days12hours
23572680days11hours23941917days10hours24352078days10hours...

RAWandLONGRAWDatatypes
TheRAWandLONGRAWdatatypesstoredatathatisnottobeexplicitlyconvertedbyOracleDatabasewhen
movingdatabetweendifferentsystems.Thesedatatypesareintendedforbinarydataorbytestrings.For
example,youcanuseLONGRAWtostoregraphics,sound,documents,orarraysofbinarydata,forwhich
theinterpretationisdependentontheuse.

OraclestronglyrecommendsthatyouconvertLONGRAWcolumnstobinaryLOB(BLOB)columns.LOB
columnsaresubjecttofarfewerrestrictionsthanLONGcolumns.SeeTO_LOB(functions193.htm#i79464)for
moreinformation.
RAWisavariablelengthdatatypelikeVARCHAR2,exceptthatOracleNet(whichconnectsusersessionsto

theinstance)andtheOracleimportandexportutilitiesdonotperformcharacterconversionwhen
transmittingRAWorLONGRAWdata.Incontrast,OracleNetandtheOracleimportandexportutilities
automaticallyconvertCHAR,VARCHAR2,andLONGdatafromthedatabasecharactersettotheusersession
characterset.Ifthetwocharactersetsaredifferent,youcansettheusersessioncharactersetwiththe
NLS_LANGUAGEparameteroftheALTERSESSIONstatement.
WhenOracleautomaticallyconvertsRAWorLONGRAWdatatoandfromCHARdata,thebinarydatais
representedinhexadecimalform,withonehexadecimalcharacterrepresentingeveryfourbitsofRAWdata.
Forexample,onebyteofRAWdatawithbits11001011isdisplayedandenteredasCB.

LargeObject(LOB)Datatypes
ThebuiltinLOBdatatypesBLOB,CLOB,andNCLOB(storedinternally)andBFILE(storedexternally)can
storelargeandunstructureddatasuchastext,image,video,andspatialdata.ThesizeofBLOB,CLOB,and
NCLOBdatacanbeupto(2321bytes)*(thevalueoftheCHUNKparameterofLOBstorage).Ifthe

tablespacesinyourdatabaseareofstandardblocksize,andifyouhaveusedthedefaultvalueofthe
CHUNKparameterofLOBstoragewhencreatingaLOBcolumn,thenthisisequivalentto(2321bytes)*
(databaseblocksize).BFILEdatacanbeupto2641bytes,althoughyouroperatingsystemmayimpose
restrictionsonthismaximum.
Whencreatingatable,youcanoptionallyspecifydifferenttablespaceandstoragecharacteristicsforLOB
columnsorLOBobjectattributesfromthosespecifiedforthetable.
CLOB,NCLOB,andBLOBvaluesuptoapproximately4000bytesarestoredinlineifyouenablestoragein

rowatthetimetheLOBcolumniscreated.LOBsgreaterthan4000bytesarealwaysstoredexternally.
RefertoENABLESTORAGEINROW(statements_7002.htm#BABHDBGB)formoreinformation.
LOBcolumnscontainLOBlocatorsthatcanrefertointernal(inthedatabase)orexternal(outsidethe
database)LOBvalues.SelectingaLOBfromatableactuallyreturnstheLOBlocatorandnottheentire
LOBvalue.TheDBMS_LOBpackageandOracleCallInterface(OCI)operationsonLOBsareperformed
throughtheselocators.
LOBsaresimilartoLONGandLONGRAWtypes,butdifferinthefollowingways:

LOBscanbeattributesofanobjecttype(userdefineddatatype).
TheLOBlocatorisstoredinthetablecolumn,eitherwithorwithouttheactualLOBvalue.BLOB,NCLOB,
andCLOBvaluescanbestoredinseparatetablespaces.BFILEdataisstoredinanexternalfileonthe
server.

WhenyouaccessaLOBcolumn,thelocatorisreturned.
ALOBcanbeupto(2321bytes)*(databaseblocksize)insize.BFILEdatacanbeupto2641bytes,
althoughyouroperatingsystemmayimposerestrictionsonthismaximum.
LOBspermitefficient,random,piecewiseaccesstoandmanipulationofdata.
YoucandefinemorethanoneLOBcolumninatable.
WiththeexceptionofNCLOB,youcandefineoneormoreLOBattributesinanobject.
YoucandeclareLOBbindvariables.
YoucanselectLOBcolumnsandLOBattributes.
YoucaninsertanewroworupdateanexistingrowthatcontainsoneormoreLOBcolumnsoranobject
withoneormoreLOBattributes.Inupdateoperations,youcansettheinternalLOBvaluetoNULL,
empty,orreplacetheentireLOBwithdata.YoucansettheBFILEtoNULLormakeitpointtoadifferent
file.
YoucanupdateaLOBrowcolumnintersectionoraLOBattributewithanotherLOBrowcolumn
intersectionorLOBattribute.
YoucandeletearowcontainingaLOBcolumnorLOBattributeandtherebyalsodeletetheLOBvalue.
ForBFILEs,theactualoperatingsystemfileisnotdeleted.

YoucanaccessandpopulaterowsofaninlineLOBcolumn(aLOBcolumnstoredinthedatabase)ora
LOBattribute(anattributeofanobjecttypecolumnstoredinthedatabase)simplybyissuinganINSERTor
UPDATEstatement.

RestrictionsonLOBColumns
LOBcolumnsaresubjecttoanumberofrulesandrestrictions.SeeOracleDatabaseSecureFilesand
LargeObjectsDeveloper'sGuide(../../appdev.111/b28393/adlob_working.htm#ADLOB2010)foracompletelisting.

SeeAlso:
OracleDatabasePL/SQLPackagesandTypesReference(../../appdev.111/b28419/d_lob.htm#ARPLS600)
andOracleCallInterfaceProgrammer'sGuide(http://www.oracle.com/pls/topic/lookup?ctx=db111&id=LNOCI070)
formoreinformationabouttheseinterfacesandLOBs
themodify_col_propertiesclauseofALTERTABLE(statements_3001.htm#CJAHHIBI)andTO_LOB
(functions193.htm#i79464)formoreinformationonconvertingLONGcolumnstoLOBcolumns

BFILEDatatype
TheBFILEdatatypeenablesaccesstobinaryfileLOBsthatarestoredinfilesystemsoutsideOracle
Database.ABFILEcolumnorattributestoresaBFILElocator,whichservesasapointertoabinaryfileon
theserverfilesystem.Thelocatormaintainsthedirectorynameandthefilename.
YoucanchangethefilenameandpathofaBFILEwithoutaffectingthebasetablebyusingtheBFILENAME
function.RefertoBFILENAME(functions012.htm#i76871)formoreinformationonthisbuiltinSQLfunction.
BinaryfileLOBsdonotparticipateintransactionsandarenotrecoverable.Rather,theunderlying
operatingsystemprovidesfileintegrityanddurability.BFILEdatacanbeupto2641bytes,althoughyour
operatingsystemmayimposerestrictionsonthismaximum.
ThedatabaseadministratormustensurethattheexternalfileexistsandthatOracleprocesseshave
operatingsystemreadpermissionsonthefile.
TheBFILEdatatypeenablesreadonlysupportoflargebinaryfiles.Youcannotmodifyorreplicatesucha
file.OracleprovidesAPIstoaccessfiledata.Theprimaryinterfacesthatyouusetoaccessfiledataare
theDBMS_LOBpackageandOracleCallInterface(OCI).

SeeAlso:
OracleDatabaseSecureFilesandLargeObjectsDeveloper'sGuide
(../../appdev.111/b28393/adlob_bfile_ops.htm#ADLOB012)andOracleCallInterfaceProgrammer'sGuide
(http://www.oracle.com/pls/topic/lookup?ctx=db111&id=LNOCI070)formoreinformationaboutLOBsandCREATE

DIRECTORY(statements_5007.htm#i2061958)

BLOBDatatype
TheBLOBdatatypestoresunstructuredbinarylargeobjects.BLOBobjectscanbethoughtofasbitstreams
withnocharactersetsemantics.BLOBobjectscanstorebinarydataupto(4gigabytes1)*(thevalueof
theCHUNKparameterofLOBstorage).Ifthetablespacesinyourdatabaseareofstandardblocksize,and
ifyouhaveusedthedefaultvalueoftheCHUNKparameterofLOBstoragewhencreatingaLOBcolumn,
thenthisisequivalentto(4gigabytes1)*(databaseblocksize).
BLOBobjectshavefulltransactionalsupport.ChangesmadethroughSQL,theDBMS_LOBpackage,or

OracleCallInterface(OCI)participatefullyinthetransaction.BLOBvaluemanipulationscanbecommitted
androlledback.However,youcannotsaveaBLOBlocatorinaPL/SQLorOCIvariableinonetransaction
andthenuseitinanothertransactionorsession.

CLOBDatatype
TheCLOBdatatypestoressinglebyteandmultibytecharacterdata.Bothfixedwidthandvariablewidth
charactersetsaresupported,andbothusethedatabasecharacterset.CLOBobjectscanstoreupto(4
gigabytes1)*(thevalueoftheCHUNKparameterofLOBstorage)ofcharacterdata.Ifthetablespacesin

yourdatabaseareofstandardblocksize,andifyouhaveusedthedefaultvalueoftheCHUNKparameterof
LOBstoragewhencreatingaLOBcolumn,thenthisisequivalentto(4gigabytes1)*(databaseblock
size).
CLOBobjectshavefulltransactionalsupport.ChangesmadethroughSQL,theDBMS_LOBpackage,or

OracleCallInterface(OCI)participatefullyinthetransaction.CLOBvaluemanipulationscanbecommitted
androlledback.However,youcannotsaveaCLOBlocatorinaPL/SQLorOCIvariableinonetransaction
andthenuseitinanothertransactionorsession.

NCLOBDatatype
TheNCLOBdatatypestoresUnicodedata.Bothfixedwidthandvariablewidthcharactersetsare
supported,andbothusethenationalcharacterset.NCLOBobjectscanstoreupto(4gigabytes1)*(the
valueoftheCHUNKparameterofLOBstorage)ofcharactertextdata.Ifthetablespacesinyourdatabase
areofstandardblocksize,andifyouhaveusedthedefaultvalueoftheCHUNKparameterofLOBstorage
whencreatingaLOBcolumn,thenthisisequivalentto(4gigabytes1)*(databaseblocksize).
NCLOBobjectshavefulltransactionalsupport.ChangesmadethroughSQL,theDBMS_LOBpackage,or

OCIparticipatefullyinthetransaction.NCLOBvaluemanipulationscanbecommittedandrolledback.
However,youcannotsaveanNCLOBlocatorinaPL/SQLorOCIvariableinonetransactionandthenuseit
inanothertransactionorsession.

SeeAlso:
OracleDatabaseGlobalizationSupportGuide(../../server.111/b28298/ch6unicode.htm#NLSPG006)for
informationonUnicodedatatypesupport

RowidDatatypes
Eachrowinthedatabasehasanaddress.Thesectionsthatfollowdescribethetwoformsofrowaddress
inanOracleDatabase.

ROWIDDatatype
TherowsinheaporganizedtablesthatarenativetoOracleDatabasehaverowaddressescalledrowids.
YoucanexaminearowidrowaddressbyqueryingthepseudocolumnROWID.Valuesofthispseudocolumn
arestringsrepresentingtheaddressofeachrow.ThesestringshavethedatatypeROWID.Youcanalso
createtablesandclustersthatcontainactualcolumnshavingtheROWIDdatatype.OracleDatabasedoes
notguaranteethatthevaluesofsuchcolumnsarevalidrowids.RefertoChapter3,"Pseudocolumns"
(pseudocolumns.htm#g1020307)formoreinformationontheROWIDpseudocolumn.

Note:
BeginningwithOracle8,OracleSQLincorporatedanextendedformatforrowidstoefficiently
supportpartitionedtablesandindexesandtablespacerelativedatablockaddresseswithout
ambiguity.IfyouarerunningVersion7ofthedatabaseandyouintendtoupgrade,usethe

DBMS_ROWIDpackagetomigraterowidsinyourdatatotheextendedformat.RefertoOracle

DatabasePL/SQLPackagesandTypesReferenceforinformationonDBMS_ROWID
(../../appdev.111/b28419/d_rowid.htm#ARPLS053)andtoOracleDatabaseUpgradeGuide
(../../server.111/b28300/preup.htm#UPGRD12358)forinformationonupgradingfromOracle7.

Rowidscontainthefollowinginformation:

Thedatablockofthedatafilecontainingtherow.Thelengthofthisstringdependsonyouroperating
system.
Therowinthedatablock.
Thedatabasefilecontainingtherow.Thefirstdatafilehasthenumber1.Thelengthofthisstring
dependsonyouroperatingsystem.
Thedataobjectnumber,whichisanidentificationnumberassignedtoeverydatabasesegment.You
canretrievethedataobjectnumberfromthedatadictionaryviewsUSER_OBJECTS,DBA_OBJECTS,and
ALL_OBJECTS.Objectsthatsharethesamesegment(clusteredtablesinthesamecluster,forexample)

havethesameobjectnumber.

Rowidsarestoredasbase64valuesthatcancontainthecharactersAZ,az,09,andtheplussign(+)
andforwardslash(/).Rowidsarenotavailabledirectly.YoucanusethesuppliedpackageDBMS_ROWIDto
interpretrowidcontents.Thepackagefunctionsextractandprovideinformationonthefourrowidelements
listedabove.

SeeAlso:
OracleDatabasePL/SQLPackagesandTypesReference(../../appdev.111/b28419/d_rowid.htm#ARPLS053)for
informationonthefunctionsavailablewiththeDBMS_ROWIDpackageandhowtousethem

UROWIDDatatype
Therowsofsometableshaveaddressesthatarenotphysicalorpermanentorwerenotgeneratedby
OracleDatabase.Forexample,therowaddressesofindexorganizedtablesarestoredinindexleaves,
whichcanmove.Rowidsofforeigntables(suchasDB2tablesaccessedthroughagateway)arenot
standardOraclerowids.
Oracleusesuniversalrowids(urowids)tostoretheaddressesofindexorganizedandforeigntables.
Indexorganizedtableshavelogicalurowidsandforeigntableshaveforeignurowids.Bothtypesofurowid
arestoredintheROWIDpseudocolumn(asarethephysicalrowidsofheaporganizedtables).
Oraclecreateslogicalrowidsbasedontheprimarykeyofthetable.Thelogicalrowidsdonotchangeas
longastheprimarykeydoesnotchange.TheROWIDpseudocolumnofanindexorganizedtablehasa
datatypeofUROWID.YoucanaccessthispseudocolumnasyouwouldtheROWIDpseudocolumnofaheap

organizedtable(usingaSELECT...ROWIDstatement).Ifyouwanttostoretherowidsofanindex
organizedtable,thenyoucandefineacolumnoftypeUROWIDforthetableandretrievethevalueofthe
ROWIDpseudocolumnintothatcolumn.

Note:
Heaporganizedtableshavephysicalrowids.Oracledoesnotrecommendthatyouspecifya
columnofdatatypeUROWIDforaheaporganizedtable.

ANSI,DB2,andSQL/DSDatatypes
SQLstatementsthatcreatetablesandclusterscanalsouseANSIdatatypesanddatatypesfromtheIBM
productsSQL/DSandDB2.OraclerecognizestheANSIorIBMdatatypenamethatdiffersfromtheOracle
Databasedatatypename.ItconvertsthedatatypetotheequivalentOracledatatype,recordstheOracle
datatypeasthenameofthecolumndatatype,andstoresthecolumndataintheOracledatatypebasedon
theconversionsshowninthetablesthatfollow.
Table26ANSIDatatypesConvertedtoOracleDatatypes
ANSISQLDatatype

OracleDatatype

CHARACTER(n)

CHAR(n)

CHAR(n)

CHARACTERVARYING(n)

VARCHAR2(n)

CHARVARYING(n)

NATIONALCHARACTER(n)

NCHAR(n)

NATIONALCHAR(n)
NCHAR(n)

NATIONALCHARACTERVARYING(n)
NATIONALCHARVARYING(n)
NCHARVARYING(n)

NVARCHAR2(n)

NUMERIC[(p,s)]

NUMBER(p,s)

DECIMAL[(p,s)](Notea)

INTEGER

NUMBER(38)

INT
SMALLINT

FLOAT(Noteb)

FLOAT(126)

DOUBLEPRECISION(Notec)

FLOAT(126)

REAL(Noted)

FLOAT(63)

Notes:

1.

a. TheNUMERICandDECIMALdatatypescanspecifyonlyfixedpointnumbers.Forthose
datatypes,thescale(s)defaultsto0.
b. TheFLOATdatatypeisafloatingpointnumberwithabinaryprecisionb.Thedefault
precisionforthisdatatypeis126binary,or38decimal.
c. TheDOUBLEPRECISIONdatatypeisafloatingpointnumberwithbinaryprecision126.
d. TheREALdatatypeisafloatingpointnumberwithabinaryprecisionof63,or18decimal.

DonotdefinecolumnswiththefollowingSQL/DSandDB2datatypes,becausetheyhaveno
correspondingOracledatatype:

GRAPHIC
LONGVARGRAPHIC
VARGRAPHIC
TIME

NotethatdataoftypeTIMEcanalsobeexpressedasOracledatetimedata.

SeeAlso:
Datatypes(../../server.111/b28286/sql_elements001.htm#SQLRF0021)inOracleDatabaseSQLLanguage
Reference(../../server.111/b28286/toc.htm)
Table27SQL/DSandDB2DatatypesConvertedtoOracleDatatypes
SQL/DSorDB2Datatype

OracleDatatype

CHARACTER(n)

CHAR(n)

VARCHAR(n)

VARCHAR(n)

LONGVARCHAR

LONG

DECIMAL(p,s)(a)

NUMBER(p,s)

INTEGER

NUMBER(38)

SMALLINT

FLOAT(b)

NUMBER

Notes:

1.

a. TheDECIMALdatatypecanspecifyonlyfixedpointnumbers.Forthisdatatype,sdefaultsto
0.
b. TheFLOATdatatypeisafloatingpointnumberwithabinaryprecisionb.Thedefault
precisionforthisdatatypeis126binaryor38decimal.

UserDefinedTypes
UserdefineddatatypesuseOraclebuiltindatatypesandotheruserdefineddatatypesasthebuilding
blocksofobjecttypesthatmodelthestructureandbehaviorofdatainapplications.Thesectionsthat
followdescribethevariouscategoriesofuserdefinedtypes.

SeeAlso:
OracleDatabaseConcepts(../../server.111/b28318/datatype.htm#CNCPT012)forinformationaboutOracle
builtindatatypes
CREATETYPE(statements_8001.htm#BABHJHEB)andtheCREATETYPEBODY
(statements_8002.htm#i2064997)forinformationaboutcreatinguserdefinedtypes
OracleDatabaseObjectRelationalDeveloper'sGuide(../../appdev.111/b28371/adobjdes.htm#ADOBJ008)for
informationaboutusinguserdefinedtypes

ObjectTypes
Objecttypesareabstractionsoftherealworldentities,suchaspurchaseorders,thatapplicationprograms
dealwith.Anobjecttypeisaschemaobjectwiththreekindsofcomponents:

Aname,whichidentifiestheobjecttypeuniquelywithinthatschema.
Attributes,whicharebuiltintypesorotheruserdefinedtypes.Attributesmodelthestructureofthe
realworldentity.
Methods,whicharefunctionsorprocedureswritteninPL/SQLandstoredinthedatabase,orwrittenin
alanguagelikeCorJavaandstoredexternally.Methodsimplementoperationstheapplicationcan
performontherealworldentity.

REFDatatypes
Anobjectidentifier(representedbythekeywordOID)uniquelyidentifiesanobjectandenablesyouto
referencetheobjectfromotherobjectsorfromrelationaltables.AdatatypecategorycalledREFrepresents
suchreferences.AREFdatatypeisacontainerforanobjectidentifier.REFvaluesarepointerstoobjects.
WhenaREFvaluepointstoanonexistentobject,theREFissaidtobe"dangling".AdanglingREFis
differentfromanullREF.TodeterminewhetheraREFisdanglingornot,usetheconditionIS[NOT]
DANGLING.Forexample,givenobjectviewoc_ordersinthesampleschemaoe,thecolumn
customer_refisoftypeREFtotypecustomer_typ,whichhasanattributecust_email:

SELECTo.customer_ref.cust_emailFROMoc_ordersoWHEREo.customer_refISNOT
DANGLING

Varrays
Anarrayisanorderedsetofdataelements.Allelementsofagivenarrayareofthesamedatatype.Each
elementhasanindex,whichisanumbercorrespondingtothepositionoftheelementinthearray.
Thenumberofelementsinanarrayisthesizeofthearray.Oraclearraysareofvariablesize,whichiswhy
theyarecalledvarrays.Youmustspecifyamaximumsizewhenyoudeclarethevarray.
Whenyoudeclareavarray,itdoesnotallocatespace.Itdefinesatype,whichyoucanuseas:

Thedatatypeofacolumnofarelationaltable
Anobjecttypeattribute
APL/SQLvariable,parameter,orfunctionreturntype

Oraclenormallystoresanarrayobjecteitherinline(aspartoftherowdata)oroutofline(inaLOB),
dependingonitssize.However,ifyouspecifyseparatestoragecharacteristicsforavarray,thenOracle
storesitoutofline,regardlessofitssize.Refertothevarray_col_properties(statements_7002.htm#i2143624)of
CREATETABLE(statements_7002.htm#i2095331)formoreinformationaboutvarraystorage.

NestedTables
Anestedtabletypemodelsanunorderedsetofelements.Theelementsmaybebuiltintypesoruser
definedtypes.Youcanviewanestedtableasasinglecolumntableor,ifthenestedtableisanobject
type,asamulticolumntable,withacolumnforeachattributeoftheobjecttype.
Anestedtabledefinitiondoesnotallocatespace.Itdefinesatype,whichyoucanusetodeclare:

Thedatatypeofacolumnofarelationaltable
Anobjecttypeattribute
APL/SQLvariable,parameter,orfunctionreturntype

Whenanestedtableappearsasthetypeofacolumninarelationaltableorasanattributeofthe
underlyingobjecttypeofanobjecttable,Oraclestoresallofthenestedtabledatainasingletable,whichit
associateswiththeenclosingrelationalorobjecttable.

OracleSuppliedTypes

OracleprovidesSQLbasedinterfacesfordefiningnewtypeswhenthebuiltinorANSIsupportedtypes
arenotsufficient.ThebehaviorforthesetypescanbeimplementedinC/C++,Java,orPL/SQL.Oracle
Databaseautomaticallyprovidesthelowlevelinfrastructureservicesneededforinputoutput,
heterogeneousclientsideaccessfornewdatatypes,andoptimizationsfordatatransfersbetweenthe
applicationandthedatabase.
Theseinterfacescanbeusedtobuilduserdefined(orobject)typesandarealsousedbyOracletocreate
somecommonlyusefuldatatypes.Severalsuchdatatypesaresuppliedwiththeserver,andtheyserve
bothbroadhorizontalapplicationareas(forexample,theAnytypes)andspecificverticalones(for
example,thespatialtypes).
TheOraclesuppliedtypes,alongwithcrossreferencestothedocumentationoftheirimplementationand
use,aredescribedinthefollowingsections:

AnyTypes(#i107578)
XMLTypes(#i160550)
SpatialTypes(#i107588)
MediaTypes(#i121058)

AnyTypes
TheAnytypesprovidehighlyflexiblemodelingofprocedureparametersandtablecolumnswherethe
actualtypeisnotknown.Thesedatatypesletyoudynamicallyencapsulateandaccesstypedescriptions,
datainstances,andsetsofdatainstancesofanyotherSQLtype.ThesetypeshaveOCIandPL/SQL
interfacesforconstructionandaccess.

ANYTYPE
ThistypecancontainatypedescriptionofanynamedSQLtypeorunnamedtransienttype.

ANYDATA
Thistypecontainsaninstanceofagiventype,withdata,plusadescriptionofthetype.ANYDATAcanbe
usedasatablecolumndatatypeandletsyoustoreheterogeneousvaluesinasinglecolumn.Thevalues
canbeofSQLbuiltintypesaswellasuserdefinedtypes.

ANYDATASET
Thistypecontainsadescriptionofagiventypeplusasetofdatainstancesofthattype.ANYDATASETcan
beusedasaprocedureparameterdatatypewheresuchflexibilityisneeded.Thevaluesofthedata
instancescanbeofSQLbuiltintypesaswellasuserdefinedtypes.

SeeAlso:

OracleDatabasePL/SQLPackagesandTypesReferenceforinformationontheANYTYPE
(../../appdev.111/b28419/t_anytyp.htm#ARPLS079),ANYDATA(../../appdev.111/b28419/t_anydat.htm#ARPLS077),and

ANYDATASET(../../appdev.111/b28419/t_anyset.htm#ARPLS078)types

XMLTypes
ExtensibleMarkupLanguage(XML)isastandardformatdevelopedbytheWorldWideWebConsortium
(W3C)forrepresentingstructuredandunstructureddataontheWorldWideWeb.Universalresource
identifiers(URIs)identifyresourcessuchasWebpagesanywhereontheWeb.Oracleprovidestypesto
handleXMLandURIdata,aswellasaclassofURIscalledDBURIReftypestoaccessdatastoredwithin
thedatabaseitself.ItalsoprovidesasetoftypestostoreandaccessbothexternalandinternalURIsfrom
withinthedatabase.

XMLType
ThisOraclesuppliedtypecanbeusedtostoreandqueryXMLdatainthedatabase.XMLTypehas
memberfunctionsyoucanusetoaccess,extract,andquerytheXMLdatausingXPathexpressions.
XPathisanotherstandarddevelopedbytheW3CcommitteetotraverseXMLdocuments.OracleXMLType
functionssupportmanyW3CXPathexpressions.OraclealsoprovidesasetofSQLfunctionsandPL/SQL
packagestocreateXMLTypevaluesfromexistingrelationalorobjectrelationaldata.
XMLTypeisasystemdefinedtype,soyoucanuseitasanargumentofafunctionorasthedatatypeofa

tableorviewcolumn.YoucanalsocreatetablesandviewsofXMLType.WhenyoucreateanXMLType
columninatable,youcanchoosetostoretheXMLdatainaCLOBcolumn,asbinaryXML(stored
internallyasaCLOB),orobjectrelationally.
Youcanalsoregistertheschema(usingtheDBMS_XMLSCHEMApackage)andcreateatableorcolumn
conformingtotheregisteredschema.InthiscaseOraclestorestheXMLdatainunderlyingobject
relationalcolumnsbydefault,butyoucanspecifystorageinaCLOBorbinaryXMLcolumnevenfor
schemabaseddata.
QueriesandDMLonXMLTypecolumnsoperatethesameregardlessofthestoragemechanism.

SeeAlso:
OracleXMLDBDeveloper'sGuide(../../appdev.111/b28369/xdb04cre.htm#ADXDB0400)forinformationabout
usingXMLTypecolumns

URIDatatypes
OraclesuppliesafamilyofURItypesURIType,DBURIType,XDBURIType,andHTTPURITypewhichare
relatedbyaninheritancehierarchy.URITypeisanobjecttypeandtheothersaresubtypesofURIType.
SinceURITypeisthesupertype,youcancreatecolumnsofthistypeandstoreDBURITypeor
HTTPURITypetypeinstancesinthiscolumn.

HTTPURIType
YoucanuseHTTPURITypetostoreURLstoexternalWebpagesortofiles.Oracleaccessesthesefiles
usingHTTP(HypertextTransferProtocol).
XDBURIType
YoucanuseXDBURITypetoexposedocumentsintheXMLdatabasehierarchyasURIsthatcanbe
embeddedinanyURITypecolumninatable.TheXDBURITypeconsistsofaURL,whichcomprisesthe
hierarchicalnameoftheXMLdocumenttowhichitrefersandanoptionalfragmentrepresentingtheXPath
syntax.ThefragmentisseparatedfromtheURLpartbyapoundsign(#).Thefollowinglinesareexamples
ofXDBURIType:
/home/oe/doc1.xml/home/oe/doc1.xml#/orders/order_item

DBURIType
DBURITypecanbeusedtostoreDBURIRefvalues,whichreferencedatainsidethedatabase.Storing
DBURIRefvaluesletsyoureferencedatastoredinsideoroutsidethedatabaseandaccessthedata

consistently.
DBURIRefvaluesuseanXPathlikerepresentationtoreferencedatainsidethedatabase.Ifyouimagine

thedatabaseasanXMLtree,thenyouwouldseethetables,rows,andcolumnsaselementsintheXML
document.Forexample,thesamplehumanresourcesuserhrwouldseethefollowingXMLtree:
<HR><EMPLOYEES><ROW><EMPLOYEE_ID>205</EMPLOYEE_ID>
<LAST_NAME>Higgins</LAST_NAME><SALARY>12000</SALARY>..<!othercolumns>
</ROW>...<!otherrows></EMPLOYEES><!othertables..></HR><!
otheruserschemasonwhichyouhavesomeprivilegeon..>

TheDBURIRefisanXPathexpressionoverthisvirtualXMLdocument.SotoreferencetheSALARYvalue
intheEMPLOYEEStablefortheemployeewithemployeenumber205,youcanwriteaDBURIRefas,
/HR/EMPLOYEES/ROW[EMPLOYEE_ID=205]/SALARY

Usingthismodel,youcanreferencedatastoredinCLOBcolumnsorothercolumnsandexposethemas
URLstotheexternalworld.

URIFactoryPackage
OraclealsoprovidestheURIFactorypackage,whichcancreateandreturninstancesofthevarious
subtypesoftheURITypes.ThepackageanalyzestheURLstring,identifiesthetypeofURL(HTTP,DBURI,
andsoon),andcreatesaninstanceofthesubtype.TocreateaDBURIinstance,theURLmuststartwith
theprefix/oradb.Forexample,URIFactory.getURI('/oradb/HR/EMPLOYEES')wouldcreatea
DBURITypeinstanceandURIFactory.getUri('/sys/schema')wouldcreateanXDBURITypeinstance.

SeeAlso:

OracleDatabaseObjectRelationalDeveloper'sGuide(../../appdev.111/b28371/adobjbas.htm#ADOBJ00205)
forgeneralinformationonobjecttypesandtypeinheritance
OracleXMLDBDeveloper'sGuide(../../appdev.111/b28369/xdb15dbu.htm#ADXDB1900)formoreinformation
aboutthesesuppliedtypesandtheirimplementation
OracleStreamsAdvancedQueuingUser'sGuide(../../server.111/b28420/aq_intro.htm#ADQUE0100)for
informationaboutusingXMLTypewithOracleAdvancedQueuing

SpatialTypes
OracleSpatialisdesignedtomakespatialdatamanagementeasierandmorenaturaltousersoflocation
enabledapplications,geographicinformationsystem(GIS)applications,andgeoimagingapplications.
AfterthespatialdataisstoredinanOracledatabase,youcaneasilymanipulate,retrieve,andrelateitto
alltheotherdatastoredinthedatabase.Thefollowingdatatypesareavailableonlyifyouhaveinstalled
OracleSpatial.

SDO_GEOMETRY
Thegeometricdescriptionofaspatialobjectisstoredinasinglerow,inasinglecolumnofobjecttype
SDO_GEOMETRYinauserdefinedtable.AnytablethathasacolumnoftypeSDO_GEOMETRYmusthave
anothercolumn,orsetofcolumns,thatdefinesauniqueprimarykeyforthattable.Tablesofthissortare
sometimescalledgeometrytables.
TheSDO_GEOMETRYobjecttypehasthefollowingdefinition:
CREATETYPESDO_GEOMETRYASOBJECT(sgo_gtypeNUMBER,sdo_sridNUMBER,sdo_point
SDO_POINT_TYPE,sdo_elem_infoSDO_ELEM_INFO_ARRAY,sdo_ordinates
SDO_ORDINATE_ARRAY)/

SDO_TOPO_GEOMETRY
Thistypedescribesatopologygeometry,whichisstoredinasinglerow,inasinglecolumnofobjecttype
SDO_TOPO_GEOMETRYinauserdefinedtable.
TheSDO_TOPO_GEOMETRYobjecttypehasthefollowingdefinition:
CREATETYPESDO_TOPO_GEOMETRYASOBJECT(tg_typeNUMBER,tg_idNUMBER,
tg_layer_idNUMBER,topology_idNUMBER)/

SDO_GEORASTER

IntheGeoRasterobjectrelationalmodel,arastergridorimageobjectisstoredinasinglerow,inasingle
columnofobjecttypeSDO_GEORASTERinauserdefinedtable.TablesofthissortarecalledGeoRaster
tables.
TheSDO_GEORASTERobjecttypehasthefollowingdefinition:
CREATETYPESDO_GEORASTERASOBJECT(rasterTypeNUMBER,spatialExtent
SDO_GEOMETRY,rasterDataTableVARCHAR2(32),rasterIDNUMBER,metadataXMLType)/

SeeAlso:
OracleSpatialDeveloper'sGuide(../../appdev.111/b28400/sdo_objrelschema.htm#SPATL020),OracleSpatial
TopologyandNetworkDataModelsDeveloper'sGuide
(../../appdev.111/b28399/sdo_topo_concepts.htm#TOPOL100),andOracleSpatialGeoRasterDeveloper'sGuide
(../../appdev.111/b28398/geor_datatypes_metadata.htm#GEORS200)forinformationonthefullimplementationofthe

spatialdatatypesandguidelinesforusingthem

MediaTypes
OracleMultimediausesobjecttypes,similartoJavaorC++classes,todescribemultimediadata.An
instanceoftheseobjecttypesconsistsofattributes,includingmetadataandthemediadata,andmethods.
TheMultimediadatatypesarecreatedintheORDSYSschema.Publicsynonymsexistforallthedatatypes,
soyoucanaccessthemwithoutspecifyingtheschemaname.

SeeAlso:
OracleMultimediaReference(../../appdev.111/b28414/ch_imgref.htm#AIVUG6000)forinformationonthe
implementationofthesetypesandguidelinesforusingthem

ORDAudio
TheORDAudioobjecttypesupportsthestorageandmanagementofaudiodata.

ORDImage
TheORDImageobjecttypesupportsthestorageandmanagementofimagedata.

ORDVideo
TheORDVideoobjecttypesupportsthestorageandmanagementofvideodata.

ORDDoc
TheORDDocobjecttypesupportsstorageandmanagementofanytypeofmediadata,includingaudio,
imageandvideodata.Usethistypewhenyouwantallmediatobestoredinasinglecolumn.

ORDDicom
TheORDDicomobjecttypesupportsthestorageandmanagementofDigitalImagingandCommunications
inMedicine(DICOM),theformatuniversallyrecognizedasthestandardformedicalimaging.
ThefollowingdatatypesprovidecompliancewiththeISOIEC132495StillImagestandard,commonly
referredtoasSQL/MMStillImage.

SI_StillImage
TheSI_StillImageobjecttyperepresentsdigitalimageswithinherentimagecharacteristicssuchas
height,width,andformat.

SI_Color
TheSI_Colorobjecttypeencapsulatescolorvalues.

SI_AverageColor
TheSI_AverageColorobjecttyperepresentsafeaturethatcharacterizesanimagebyitsaveragecolor.

SI_ColorHistogram
TheSI_ColorHistogramobjecttyperepresentsafeaturethatcharacterizesanimagebytherelative
frequenciesofthecolorsexhibitedbysamplesoftherawimage.

SI_PositionalColor
Givenanimagedividedintonbymrectangles,theSI_PositionalColorobjecttyperepresentsthe
featurethatcharacterizesanimagebythenbymmostsignificantcolorsoftherectangles.

SI_Texture
TheSI_Textureobjecttyperepresentsafeaturethatcharacterizesanimagebythesizeofrepeating
items(coarseness),brightnessvariations(contrast),andpredominantdirection(directionality).

SI_FeatureList
TheSI_FeatureListobjecttypeisalistcontaininguptofouroftheimagefeaturesrepresentedbythe
precedingobjecttypes(SI_AverageColor,SI_ColorHistogram,SI_PositionalColor,and
SI_Texture),whereeachfeatureisassociatedwithafeatureweight.

ORDImageSignature
TheORDImageSignatureobjecttypehasbeendeprecatedandshouldnolongerbeenintroducedinto
yourcode.Existingoccurrencesofthisobjecttypewillcontinuetofunctionasinthepast.

ExpressionFilterType
TheOracleExpressionFilterallowsapplicationdeveloperstomanageandevaluateconditional
expressionsthatdescribeusers'interestsindata.TheExpressionFilterincludesthefollowingdatatype:

Expression
ExpressionFilterusesavirtualdatatypecalledExpressiontomanageandevaluateconditional
expressionsasdataindatabasetables.TheExpressionFiltercreatesacolumnofExpressiondatatype
fromaVARCHAR2columnbyassigninganattributesettothecolumn.Thisassignmentenablesadata
constraintthatensuresthevalidityofexpressionsstoredinthecolumn.
YoucandefineconditionsusingtheEVALUATEoperatoronanExpressiondatatypetoevaluatethe
expressionsstoredinacolumnforsomedata.IfyouareusingEnterpriseEdition,thenyoucanalsodefine
anExpressionFilterindexonacolumnofExpressiondatatypetoprocessqueriesusingtheEVALUATE
operator.

SeeAlso:
OracleDatabaseRulesManagerandExpressionFilterDeveloper'sGuide
(../../appdev.111/b31088/exprn_expconcepts.htm#EXPRN007)formoreinformationontheExpressionFilter

(http://www.oracle.com/us/legal/index.html)

ContactUs (http://www.oracle.com/us/corporate/contact/index.html)

TermsofUse(http://www.oracle.com/us/legal/terms/index.html)

(http://www.oracle.com/us/legal/privacy/index.html)

Copyright2015,Oracleand/oritsaffiliates.Allrightsreserved.

LegalNotices

YourPrivacyRights

AboutOracle(http://www.oracle.com/corporate/index.html)

(#)

Вам также может понравиться