【11g】使用REGEXP_COUNT函数统计字符串出现的次数
2017-04-24 10:16
246 查看
在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 --
原地址:http://blog.itpub.net/519536/viewspace-624634/
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 --
原地址:http://blog.itpub.net/519536/viewspace-624634/
相关文章推荐
- 【11g】使用REGEXP_COUNT函数统计字符串出现的次数
- 【11g】使用REGEXP_COUNT函数统计字符串出现的次数
- 使用REGEXP_COUNT函数统计字符串出现的次数
- swift-08-使用键值对儿统计字符在字符串中出现的次数
- 使用map集合统计字符串中字母出现的次数
- swift-08-使用键值对儿统计字符在字符串中出现的次数
- 使用shell统计字符串出现的次数,并从大到小进行排序显示
- java 使用正则表达式统计一个字符串中子字符串出现次数
- 使用Linux命令统计文件指定列中字符串出现次数
- 【shell】linux统计某一文件中字符串“sent ip”出现的次数
- javascript统计字符串内字符出现次数
- 用js实现统计字符串里面的出现次数最多的字符
- 使用map容器,统计输入的单词出现的次数
- 练习2-4:编一个程序统计文件中特定单词出现的次数(要求使用string类的运算符==来查找单词)
- [每周一算法]统计在一个字符串中各个不同字符出现的次数
- 使用TreeMap或者HashMap统计单词个数和字母出现次数
- JavaScript效率PK——统计特定字符在字符串中出现的次数
- javascript 统计字符串内某字符串出现次数
- PHP函数库06:PHP统计字符串里单词出现次数
- 统计字符串出现的次数