Oracle函數--instr()

 

instr() 返回要截取的字符串在源字符串中的位置

語法: 
instr(sourceString,destString,startPosition,appearPosition) 

參數說明:

sourceString:源字符串,要在此字符串中查找。

destString:要在sourceString中查找的字符串。

startPosition:代表在sourceString字符串中哪個位置開始查找。此參數可選,如果忽略默認爲1.如果此參數爲正數,從左向右檢索。如果爲負數,從右向左檢索。返回查找字符串在源字符串中的索引位置。

appearPosition:代表查找第幾次出現的destString,此參數可以忽略,默認爲1,設置負數會報錯。

如果destString在sourceString沒有查找到,則返回0.

Both sourceString and destString  can be any of the datatypes CHAR, VARCHAR2, NCHAR, NVARCHAR2, CLOB, or NCLOB. The value returned is of NUMBER datatype.

--返回要截取的字符串在源字符串中的位置
select instr('abc','a') from dual;                 --返回1
select instr('abc','bc') from dual;               --返回2
select instr('aB c abc','a',1,2) from dual;  --返回6
select instr('uoabc','bc',-1,1) from dual;   --返回4
select instr('abc','d') from dual;            --返回0

--startPosition參數爲負的情況
select instr('uoabcd','c',-1,1) from dual;   --返回5       --範圍:uoabcd中查找
select instr('uoabcd','c',-2,1) from dual;   --返回5       --範圍:uoabc中查找
select instr('uoabcd','c',-3,1) from dual;   --返回0       --範圍:uoab中查找

 

擴展:instrb(),instrc(),instr2(),instr4()

 

 

 



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章