在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'----------2sys@ora11g> select regexp_count ('THE PRO-NIECE WAS BORN TODAY, SO EXCITING!', 'a') "Count 'a'" from dual;Count 'a'----------03.大小写敏感匹配不加其余参数的情况下,等同于下面的全参数形式。表示对字母大小写敏感匹配(最后一个参数“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------------------------2sys@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------------------------04.大小写不敏感匹配若意欲同时匹配大写字母“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--------------------------2sys@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--------------------------25.从指定位置进行检索倒数第二个参数表示开始检索关键字的位置,如下例中的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'----------16.Oracle官方文档参考链接7.小结几近人性化的函数给Oracle 11g增色添辉不少,抛砖完毕。Good luck.secooler10.01.07-- The End --
oracle中regexp_count,【11g】使用REGEXP_COUNT函数统计字符串出现的次数
最新推荐文章于 2021-07-07 14:25:29 发布