REGEXP_REPLACE
声明
REGEXP_REPLACE(expr, pat, repl[, pos[, occurrence[, match_type]]])
说明
将字符串 expr 中匹配 pat 的子字符串替换为 repl 指定的字符串,并返回替换后的字符串。如果 expr、pat 或 repl 为 NULL,则该函数返回 NULL。
-
pos表示从表达式expr的第几个字符开始搜索,缺省为1。 -
occurrence表示将第几次 匹配替换为repl,默认为0,表示替换所有匹配的子字符串。 -
match_type表示匹配规则。有关匹配规则的详细信息,请参见 REGEXP_LIKE。
示例
SELECT REGEXP_REPLACE('OceanBase', 'a', '2');
+---------------------------------------+
| REGEXP_REPLACE('OceanBase', 'a', '2') |
+---------------------------------------+
| Oce2nB2se |
+---------------------------------------+
1 row in set (0.001 sec)
SELECT REGEXP_REPLACE('OceanBase', 'a', '2',7);
+-----------------------------------------+
| REGEXP_REPLACE('OceanBase', 'a', '2',7) |
+-----------------------------------------+
| OceanB2se |
+-----------------------------------------+
1 row in set (0.001 sec)
SELECT REGEXP_REPLACE('OceanBase', 'a', '2',1,2);
+-------------------------------------------+
| REGEXP_REPLACE('OceanBase', 'a', '2',1,2) |
+-------------------------------------------+
| OceanB2se |
+-------------------------------------------+
1 row in set (0.001 sec)