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