您的位置:首页 > 数据库 > Oracle

oracle instr函数 收藏

2011-05-13 20:45 330 查看

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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: