instr函數的使用-oracle

instr(string1,string2[,start_position[,nth_appearence]])

string1:要在此字符串中查找。

string2:要在string1中查找的字符串。

start_position:從string1開始查找的位置。可選,默認爲1,正數時,從左到右檢索,負數時,從右到左檢索。

nth_appearence:查找第幾次出現string2。可選,默認爲1,不能爲負。

注:如果沒有查找到,返回0。

 例如:

select instr('abcd','a') from dual;  --返回1
select instr('abcd','c') from dual;  --返回3
select instr('abcd','e') from dual;    --返回0

該函數可以用於模糊查詢以及判斷包含關係:

例如:

① select code, name, dept, occupation  from staff  where instr(code, '001') > 0;

  等同於

  select code, name, dept, occupation  from staff  where code like '%001%' ;

② select ccn,mas_loc from mas_loc where instr('FH,FHH,FHM',ccn)>0;

  等同於

  select ccn,mas_loc from mas_loc where ccn in ('FH','FHH','FHM');

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