更新时间:2025-01-22 GMT+08:00
regexp_count
regexp_count函数用于计算source中从start_position位置开始,匹配指定pattern的子串数。
命令格式
regexp_count(string <source>, string <pattern>[, bigint <start_position>])
参数说明
参数 | 是否必选 | 参数类型 | 说明 |
|---|---|---|---|
source | 是 | STRING | 待搜索的字符串,其他类型会返回报错。 |
pattern | 是 | STRING | STRING类型常量或正则表达式。待匹配的模型。pattern为空串或其他类型时返回报错。 |
start_position | 否 | BIGINT | BIGINT类型常量,必须大于0。其他类型或值小于等于0时返回报错。不指定时默认为1,表示从source的第一个字符开始匹配。 |
返回值说明
返回BIGINT类型的值。

- 如果没有匹配成功,返回0。
- source、pattern值为NULL时,返回NULL。
示例代码
返回4。
select regexp_count('ab0a1a2b3c', '[0-9]'); 返回3。
select regexp_count('ab0a1a2b3c', '[0-9]', 4); 返回 null。
select regexp_count('ab0a1a2b3c', null); 父主题:字符串函数

