SQL 函數 instr的用法

來源:互聯網
上載者:User

 

INSTR(C1,C2,I,J) 在一個字串中搜尋指定的字元,返回傳現指定的字元的位置;
C1    被搜尋的字串
C2    希望搜尋的字串
I     搜尋的開始位置,預設為1
J     出現的位置,預設為1
SQL> select instr("abcde",'b');

結果是2,即在字串“abcde”裡面,字串“b”出現在第2個位置。如果沒有找到,則返回0;不可能返回負數

 

 

http://dmvoiptt.oracle.com.cn/redirect.php?tid=137792&goto=lastpost

SQL> select * from grp_mem;

NAME                 ID
-------------------- ----------
group1               1.2

SQL> select * from mem_info;

        ID IP
---------- --------------------
         1 10.10.20.1
         1 10.10.20.2
         2 10.20.20.2
         2 10.20.20.1
         3 10.30.20.1

SQL> select a.name,b.ip from grp_mem a,mem_info b

      where a.name='group1' and
instr(a.id,b.id)>0;

NAME                 IP
-------------------- --------------------
group1               10.10.20.1
group1               10.10.20.2
group1               10.20.20.2
group1               10.20.20.1

SQL>

 

如:

select instr('abc123abc321','c', -1, 1) from dual //從abc123abc321找到c,從最前面,到從後開始的第一次出現開始找,返回索引值

結果為9

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.