【11g】使用REGEXP_COUNT函数统计字符串出现的次数
来源:互联网 发布:他改变了中国 知乎 编辑:程序博客网 时间:2024/04/23 21:03
在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
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/
0 0
- 【11g】使用REGEXP_COUNT函数统计字符串出现的次数
- 【11g】使用REGEXP_COUNT函数统计字符串出现的次数
- 【11g】使用REGEXP_COUNT函数统计字符串出现的次数
- 使用REGEXP_COUNT函数统计字符串出现的次数
- 【SQL】10g字符串处理函数regexp_count
- oracle 11g中regexp_count函数
- 统计字符串出现的次数
- 字符串的出现次数统计
- 统计字符串出现的次数
- 统计字符串出现的次数
- 统计字符串出现的次数
- 使用map集合统计字符串中字母出现的次数
- 字符串出现次数统计
- 统计字符串每个字符出现的次数
- 统计某字符串中某子串出现的次数
- 统计字符串各字符出现的次数
- Linux 统计某个字符串出现的次数
- 统计特定字符串出现的次数
- 关于Task的一点思考和建议
- Android NDK开发从0到1
- CSAPP笔记(概括)
- jQuery的child方法、find方法,区别?
- 游戏化思维——核心驱动力
- 【11g】使用REGEXP_COUNT函数统计字符串出现的次数
- 一个全局的定时事件发生器
- hdu 1071 The area
- PowerDesigner逆向工程,同时将comm注释转化为name显示
- Networking with URLSession: Authentication&ATS
- mysql数据库-外键
- redis存储关系性数据库数据
- 图片轮播
- Java并发编程系列之三:锁与volatile的内存语义