【11g】使用REGEXP_COUNT函數統計字串出現的次數____函數

來源:互聯網
上載者:User
Oracle11g版本中引入了 REGEXP_COUNT函數,使用這個 函數可以 統計 字串出現的 次數,小觀一下。

1.REGEXP_COUNT函數文法參考
REGEXP_COUNT (source_char, pattern [, position [, match_param]])

2.先看一下使用最少參數的效果(僅使用前兩個參數)
1)得到字串中小寫字母“a”的出現次數
sys@ora11g> select regexp_count ('The pro-niece was born today, so exciting.', 'a') "Count 'a'" from dual;

Count 'a'
----------
         2

sys@ora11g> select regexp_count ('THE PRO-NIECE WAS BORN TODAY, SO EXCITING!', 'a') "Count 'a'" from dual;

Count 'a'
----------
         0

3.大小寫敏感匹配
不加其餘參數的情況下,等同於下面的全參數形式。表示對字母大小寫敏感匹配(最後一個參數“c”表示大小寫敏感)。
sys@ora11g> select regexp_count ('The pro-niece was born today, so exciting.', 'a', 1, 'c') "Count 'a' case-sensitive" from dual;

Count 'a' case-sensitive
------------------------
                       2

sys@ora11g> select regexp_count ('THE PRO-NIECE WAS BORN TODAY, SO EXCITING!', 'a', 1, 'c') "Count 'a' case-sensitive" from dual;

Count 'a' case-sensitive
------------------------
                       0

4.大小寫不敏感匹配
若意欲同時匹配大寫字母“A”和小寫字母“a”,可以啟用“i”參數,表示大小寫不敏感。
sys@ora11g> select regexp_count ('The pro-niece was born today, so exciting.', 'a', 1, 'i') "Count 'a' case-insensitive" from dual;

Count 'a' case-insensitive
--------------------------
                         2

sys@ora11g> select regexp_count ('THE PRO-NIECE WAS BORN TODAY, SO EXCITING!', 'a', 1, 'i') "Count 'a' case-insensitive" from dual;

Count 'a' case-insensitive
--------------------------
                         2

5.從指定位置進行檢索
倒數第二個參數表示開始檢索關鍵字的位置,如下例中的17表示從字串的第17個字元處開始檢索字母a(不區分大小寫)。
sys@ora11g> select regexp_count ('The pro-niece was born today, so exciting!', 'a', 17, 'i') "Count 'a'"  from dual;

Count 'a'
----------
         1

6.Oracle官方文檔參考連結
http://download.oracle.com/docs/cd/B28359_01/server.111/b28286/functions135.htm#SQLRF20014

7.小結
幾近人性化的函數給Oracle 11g增色添輝不少,拋磚完畢。

Good luck.

secooler
10.01.07

-- The End --

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.