oracle instr函數


oracle instr函數 

在oracle PL/SQL中,instr函數返回string2在string1中出現的位置,語法如下:

instr(string1,instring2[,start_position[,nth_appearance]])
string1:被搜索的字符串
string2:在string1里面尋找的字符串
start_position:從string1中開始搜索的位置,這是個可選參數,默認為1。
 sting1中第一個字符的位置為1。如果這個參數為一個負數,那么搜索將從string1的末尾開始,並向string1的開始位置進行搜索。
nth_appearance:string2在string1中出現的次數,這是一個可選參數,默認值為1.
注意:如果string2未在string1中出現,那么instr函數的返回值為0。

實例
1.從起始位置開始搜索,第一次出現子串的位置
SQL> select instr('chen_linbo_bobo12082119','bo',1,1) from dual;
INSTR('CHEN_LINBO_BOBO12082119
------------------------------
                             9
SQL> select instr('chen_linbo_bobo12082119','bo') from dual;
INSTR('CHEN_LINBO_BOBO12082119
------------------------------
                             9

2.從后往前搜索,第二次出現子串的位置
SQL> select instr('chen_linbo_bobo12082119','bo',-1,1) from dual;
INSTR('CHEN_LINBO_BOBO12082119
------------------------------
                            14
SQL> select instr('chen_linbo_bobo12082119','bo',-1) from dual;
INSTR('CHEN_LINBO_BOBO12082119
------------------------------
                            14

3.從指定位置開始搜索
SQL> select instr('chen_linbo_bobo12082119','bo',7,3) from dual;
INSTR('CHEN_LINBO_BOBO12082119
------------------------------
                            14
SQL> select instr('chen_linbo_bobo12082119','bo',10,3) from dual;
INSTR('CHEN_LINBO_BOBO12082119
------------------------------
                             0

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM