1. 程式人生 > >oracle 資料庫存 查詢字串函式 like instr

oracle 資料庫存 查詢字串函式 like instr

INSTR()
格式一:instr( string1, string2 )
格式二:instr( string1, string2 [, start_position [, nth_appearance ] ] )
解析:string2 的值要在string1中查詢,是從start_position給出的數值(即:位置)開始在string1檢索,檢索第nth_appearance(幾)次出現string2。
例:
1 select instr('helloworld','l') from dual; --返回結果:3 預設第一次出現“l”的位置
2 select instr('helloworld','lo') from dual; --返回結果:4 即:在“lo”中,“l”開始出現的位置
3 select instr('helloworld','wo') from dual; --返回結果:6 即“w”開始出現的位置
4 select instr('helloworld','l',2,2) from dual; --返回結果:4 也就是說:在"helloworld"的第2(e)號位置開始,查詢第二次出現的“l”的位置.
查詢字串是否存在:
MySQL: select from tableName where name like '%helloworld%';
Oracle:select

from tableName where instr(name,'helloworld')>0; --這兩條語句的效果是一樣的
select instr("helloworld","l") from dual;
結果為:3 #也就是“l”第一次出現的位置序號為3
select instr("helloworld","lo") from dual;
結果為:4 #也就是“lo”第一次出現的位置為4