BetterWF

博客园 首页 新随笔 联系 订阅 管理

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

 

posted on 2012-06-20 16:33  BetterWF  阅读(6040)  评论(0编辑  收藏  举报