欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Oracle中的instr()函數(shù)應(yīng)用及使用詳解

 更新時(shí)間:2019年12月11日 10:02:24   作者:DSHORE  
這篇文章主要介紹了Oracle中的instr()函數(shù)應(yīng)用及使用詳解,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧

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

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

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

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

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

2、實(shí)例

格式一

 select instr('helloworld','l') from dual; --返回結(jié)果:3  默認(rèn)第一次出現(xiàn)“l(fā)”的位置
select instr('helloworld','lo') from dual; --返回結(jié)果:4  即“l(fā)o”同時(shí)(連續(xù))出現(xiàn),“l(fā)”的位置
select instr('helloworld','wo') from dual; --返回結(jié)果:6  即“w”開始出現(xiàn)的位置

格式二

select instr('helloworld','l',2,2) from dual; --返回結(jié)果:4  也就是說:在"helloworld"的第2(e)號(hào)位置開始,查找第二次出現(xiàn)的“l(fā)”的位置
select instr('helloworld','l',3,2) from dual; --返回結(jié)果:4  也就是說:在"helloworld"的第3(l)號(hào)位置開始,查找第二次出現(xiàn)的“l(fā)”的位置
select instr('helloworld','l',4,2) from dual; --返回結(jié)果:9  也就是說:在"helloworld"的第4(l)號(hào)位置開始,查找第二次出現(xiàn)的“l(fā)”的位置
select instr('helloworld','l',-1,1) from dual; --返回結(jié)果:9  也就是說:在"helloworld"的倒數(shù)第1(d)號(hào)位置開始,往回查找第一次出現(xiàn)的“l(fā)”的位置
select instr('helloworld','l',-2,2) from dual; --返回結(jié)果:4  也就是說:在"helloworld"的倒數(shù)第2(l)號(hào)位置開始,往回查找第二次出現(xiàn)的“l(fā)”的位置
select instr('helloworld','l',2,3) from dual; --返回結(jié)果:9  也就是說:在"helloworld"的第2(e)號(hào)位置開始,查找第三次出現(xiàn)的“l(fā)”的位置
select instr('helloworld','l',-2,3) from dual; --返回結(jié)果:3  也就是說:在"helloworld"的倒數(shù)第2(l)號(hào)位置開始,往回查找第三次出現(xiàn)的“l(fā)”的位置

注:MySQL中的模糊查詢 like 和 Oracle中的 instr() 函數(shù)有同樣的查詢效果; 如下所示:

MySQL: select * from tableName where name like '%helloworld%';
Oracle:select * from tableName where instr(name,'helloworld')>0; --這兩條語句的效果是一樣的

3、實(shí)例截圖

1、

2、

3、

4、

5、

6、

7、

8、

9、

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論