You are on page 1of 3

(//docs.oracle.com/en/) SignIn(http://www.oracle.com/webapps/redirect/signon?nexturl=https://docs.oracle.com/cd/B19306_01/server.102/b14200/functions068.

htm)

Home(/)/Database(/en/database/database.html)/OracleDatabaseOnlineDocumentation,10gRelease2(10.2)(../../index.htm)/Administration(../../nav/portal_3.htm)

DatabaseSQLReference

INSTR
Syntax

Descriptionoftheillustrationinstr.gif(img_text/instr.htm)

Purpose

TheINSTRfunctionssearchstringforsubstring.Thefunctionreturnsanintegerindicatingthepositionofthecharacterinstringthatisthefirstcharacter
ofthisoccurrence.INSTRcalculatesstringsusingcharactersasdefinedbytheinputcharacterset.INSTRBusesbytesinsteadofcharacters.INSTRCuses
Unicodecompletecharacters.INSTR2usesUCS2codepoints.INSTR4usesUCS4codepoints.

positionisannonzerointegerindicatingthecharacterofstringwhereOracleDatabasebeginsthesearch.Ifpositionisnegative,thenOraclecounts
backwardfromtheendofstringandthensearchesbackwardfromtheresultingposition.
occurrenceisanintegerindicatingwhichoccurrenceofstringOracleshouldsearchfor.Thevalueofoccurrencemustbepositive.

BothstringandsubstringcanbeanyofthedatatypesCHAR,VARCHAR2,NCHAR,NVARCHAR2,CLOB,orNCLOB.ThevaluereturnedisofNUMBERdatatype.

BothpositionandoccurrencemustbeofdatatypeNUMBER,oranydatatypethatcanbeimplicitlyconvertedtoNUMBER,andmustresolvetoaninteger.The
defaultvaluesofbothpositionandoccurrenceare1,meaningOraclebeginssearchingatthefirstcharacterofstringforthefirstoccurrenceof
substring.Thereturnvalueisrelativetothebeginningofstring,regardlessofthevalueofposition,andisexpressedincharacters.Ifthesearchis
unsuccessful(ifsubstringdoesnotappearoccurrencetimesafterthepositioncharacterofstring),thenthereturnvalueis0.

SeeAlso:
Table210,"ImplicitTypeConversionMatrix"(sql_elements002.htm#g195937)formoreinformationonimplicitconversion

Examples

ThefollowingexamplesearchesthestringCORPORATEFLOOR,beginningwiththethirdcharacter,forthestring"OR".ItreturnsthepositioninCORPORATEFLOOR
atwhichthesecondoccurrenceof"OR"begins:

SELECTINSTR('CORPORATEFLOOR','OR',3,2)"Instring"FROMDUALInstring14

Inthenextexample,Oraclecountsbackwardfromthelastcharactertothethirdcharacterfromtheend,whichisthefirstOinFLOOR.Oraclethensearches
backwardforthesecondoccurrenceofOR,andfindsthatthissecondoccurrencebeginswiththesecondcharacterinthesearchstring:

SELECTINSTR('CORPORATEFLOOR','OR',3,2)"ReversedInstring"FROMDUALReversedInstring2

Thenextexampleassumesadoublebytedatabasecharacterset.

SELECTINSTRB('CORPORATEFLOOR','OR',5,2)"Instringinbytes"FROMDUALInstringinbytes27

Page108of479
(https://docs.oracle.com/cd/B19306_01/server.102/b14200/functions069.htm)
(https://docs.oracle.com/cd/B19306_01/server.102/b14200/functions067.htm)
AboutOracle(http://www.oracle.com/corporate/index.html) ContactUs (http://www.oracle.com/us/corporate/contact/index.html) LegalNotices (http://www.oracle.com/us/legal/index.html) TermsofUse


(#)

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


Copyright2016,Oracleand/oritsaffiliates.Allrightsreserved.

You might also like