Oracle中的instr 函式 詳解及應用

2022-06-26 04:33:11 字數 2526 閱讀 2368

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

注:在oracle/plsql中,instr函式返回要擷取的字串在源字串中的位置。只檢索一次,也就是說從字元的開始到字元的結尾就結束。

格式一

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」開始出現的位置

格式二

1 select instr('helloworld','l',2,2) from dual;  --返回結果:4    也就是說:在"helloworld"的第2(e)號位置開始,查詢第二次出現的「l」的位置

2 select instr('helloworld','l',3,2) from dual; --返回結果:4 也就是說:在"helloworld"的第3(l)號位置開始,查詢第二次出現的「l」的位置

3 select instr('helloworld','l',4,2) from dual; --返回結果:9 也就是說:在"helloworld"的第4(l)號位置開始,查詢第二次出現的「l」的位置

4 select instr('helloworld','l',-1,1) from dual; --返回結果:9 也就是說:在"helloworld"的倒數第1(d)號位置開始,往回查詢第一次出現的「l」的位置

5 select instr('helloworld','l',-2,2) from dual; --返回結果:4 也就是說:在"helloworld"的倒數第2(l)號位置開始,往回查詢第二次出現的「l」的位置

6 select instr('helloworld','l',2,3) from dual; --返回結果:9 也就是說:在"helloworld"的第2(e)號位置開始,查詢第三次出現的「l」的位置

7 select instr('helloworld','l',-2,3) from dual; --返回結果:3 也就是說:在"helloworld"的倒數第2(l)號位置開始,往回查詢第三次出現的「l」的位置

注:mysql中的模糊查詢 like 和 oracle中的 instr() 函式有同樣的查詢效果; 如下所示:

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

原文出自:

Oracle中的instr函式

在oracle pl sql中,instr函式返回string2在string1中出現的位置,語法如下 例項1.從起始位置開始搜尋,第一次出現子串的位置 sql select instr chen linbo bobo12082119 bo 1,1 from dual instr chen linb...

Oracle中的instr 函式

格式一 instr string1,string2 instr 源字串,目標字串 注 在oracle plsql中,instr函式返回要擷取的字串在源字串中的位置。只檢索一次,也就是說從字元的開始到字元的結尾就結束。1 select instr helloworld l from dual 返回結果...

Oracle中 Instr 這個函式

sql charindex 字串 字段 0 charindex administrator muserid 0 oracle instr 字段,字串 1,1 0 instr muserid,administrator 1,1 0 在專案中用到了oracle中 instr 這個函式,順便仔細的再次學習...