【11g】使用REGEXP_COUNT函数统计字符串出现的次数
2013-08-25 10:59
246 查看
from http://space.itpub.net/519536/viewspace-624634
在Oracle的11g版本中引入了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 --
在Oracle的11g版本中引入了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 --
相关文章推荐
- 【11g】使用REGEXP_COUNT函数统计字符串出现的次数
- 【11g】使用REGEXP_COUNT函数统计字符串出现的次数
- 使用REGEXP_COUNT函数统计字符串出现的次数
- 使用map集合统计字符串中字母出现的次数
- java 使用正则表达式统计一个字符串中子字符串出现次数
- swift-08-使用键值对儿统计字符在字符串中出现的次数
- swift-08-使用键值对儿统计字符在字符串中出现的次数
- 使用Linux命令统计文件指定列中字符串出现次数
- 使用shell统计字符串出现的次数,并从大到小进行排序显示
- Java - 写一个方法,输入一个文件名和一个字符串,统计这个字符串在这个文件中出现的次数。
- 统计字符串中各个字符出现的次数
- 搜索出字符串中出现次数最多的字符,并统计次数
- Java UDP 统计字符串中某子串出现的次数
- C语言—统计字符串出现次数最多的字母
- c++统计字符串出现次数
- java统计字符串中单个字符出现的次数
- 统计一个字符串中字符出现的次数(带上机课时候发现学生都有很好的思路bitmap)
- 一个笔试面试经常问的问题——统计字符串中出现最多的字符及次数
- (字符串的模式匹配4.7.8)UVA 10008 What's Cryptanalysis?(统计文本中某一个字符的出现的次数,需要从小到大排序&&同次数的按字段序排序)
- Linux vi 统计字符串出现的次数