类别:

字符串函数(正则表达式)

REGEXP_COUNT

返回模式在字符串中出现的次数。

另请参阅 字符串函数(正则表达式)

语法

REGEXP_COUNT( <subject> , <pattern> [ , <position> , <parameters> ] )
Copy

实参

必填:

subject

以匹配为准。

pattern

要匹配的模式。

可选:

position

函数开始搜索匹配项时,字符串开头的字符数。

默认值:1 (搜索匹配项时,从左边的第一个字符开始)

parameters

包含一个或多个字符的字符串,指定用于搜索匹配项的参数。支持的值:

cimes

有关更多详细信息,请参阅 为正则表达式指定参数

默认:c

使用说明

排序规则详细信息

Arguments with collation specifications are currently not supported.

示例

以下示例计算单词 was 的出现次数。匹配从字符串中的第 1 个字符开始:

select regexp_count('It was the best of times, it was the worst of times', '\\bwas\\b', 1) as "result" from dual;

+--------+
| result |
|--------|
|      2 |
+--------+
Copy

以下示例说明了重叠出现的情况:

create or replace table overlap (id number, a string);
insert into overlap values (1,',abc,def,ghi,jkl,');
insert into overlap values (2,',abc,,def,,ghi,,jkl,');

select * from overlap;

select id, regexp_count(a,'[[:punct:]][[:alnum:]]+[[:punct:]]', 1, 'i') from overlap;

+----+--------------------------------------------------------------+
| ID | REGEXP_COUNT(A,'[[:PUNCT:]][[:ALNUM:]]+[[:PUNCT:]]', 1, 'I') |
|----+--------------------------------------------------------------|
|  1 |                                                            2 |
|  2 |                                                            4 |
+----+--------------------------------------------------------------+
Copy
语言: 中文