溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

Oracle中的instr()函數

發(fā)布時間:2020-07-19 18:10:59 來源:網絡 閱讀:2215 作者:MChopin 欄目:關系型數據庫

一、instr()函數的格式(俗稱:字符查找函數)

格式一:instr( string1, string2 )
/ instr(源字符串, 目標字符串)

格式二:instr( string1, string2 [, start_position [, nth_appearance ] ] )
/ instr(源字符串, 目標字符串, 起始位置, 匹配序號)

解析:string2 的值要在string1中查找,是從start_position給出的數值(即:位置)開始在string1檢索,檢索第nth_appearance(幾)次出現string2。

注:在Oracle/PLSQL中,instr函數返回要截取的字符串在源字符串中的位置。只檢索一次,也就是說從字符的開始到字符的結尾就結束。

二、實例

格式一
1、select instr('helloworld','l') from dual; --默認第一次出現“l(fā)”的位置
Oracle中的instr()函數
2、select instr('helloworld','lo') from dual; --在“l(fā)o”中,“l(fā)”開始出現的位置
Oracle中的instr()函數
3、select instr('helloworld','wo') from dual; --“w”開始出現的位置
Oracle中的instr()函數

格式二
1、select instr('helloworld','l',2,2) from dual;
--在"helloworld"的第2(e)號位置開始,查找第二次出現的“l(fā)”的位置
Oracle中的instr()函數
2、select instr('helloworld','l',3,2) from dual;
--在"helloworld"的第3(l)號位置開始,查找第二次出現的“l(fā)”的位置
Oracle中的instr()函數
3、select instr('helloworld','l',4,2) from dual;
--在"helloworld"的第4(l)號位置開始,查找第二次出現的“l(fā)”的位置
Oracle中的instr()函數
4、select instr('helloworld','l',-1,1) from dual;
--在"helloworld"的倒數第1(d)號位置開始,往回查找第一次出現的“l(fā)”的位置
Oracle中的instr()函數
5、select instr('helloworld','l',-1,2) from dual;
--在"helloworld"的倒數第1(d)號位置開始,往回查找第二次出現的“l(fā)”的位置
Oracle中的instr()函數
6、select instr('helloworld','l',2,3) from dual;
--在"helloworld"的第2(e)號位置開始,查找第三次出現的“l(fā)”的位置
Oracle中的instr()函數
7、select instr('helloworld','l',-2,3) from dual;
--在"helloworld"的倒數第2(l)號位置開始,往回查找第三次出現的“l(fā)”的位置
Oracle中的instr()函數

注:模糊查詢 like 和 instr() 函數有同樣的查詢效果:
select from table where colName like '%helloworld%';
select
from table where instr(colName ,'helloworld')>0; --這兩條語句的效果是一樣的
例:
Oracle中的instr()函數
Oracle中的instr()函數

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng)、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI