字符串替换函数
一般字符串操作函数和用于字符串搜索的函数,可参考:ClickHouse 字符串操作函数、ClickHouse 字符串搜索函数。
1. overlay
将字符串 input
中的一部分替换为另一个字符串 replace
,从基于 1 的索引 offset
开始。
语法:
overlay(s, replace, offset[, length])
参数:
-
s
:输入字符串。类型为字符串。 -
replace
:用于替换的字符串。类型为字符串。 -
offset
:整数类型(基于 1)。如果offset
为负数,则从字符串s
的末尾开始计算。 -
length
:可选参数。整数类型。length
指定了输入字符串s
中要被替换的片段的长度。如果未指定length
,则从s
中移除的字节数等于replace
的长度;否则移除length
字节。
返回值:
-
返回值为字符串类型。
示例:
SELECT overlay('My father is from Mexico.', 'mother', 4) AS res;
结果:
┌─res──────────────────────┐
│ My mother is from Mexico.│
└──────────────────────────┘
示例:
SELECT overlay('My father is from Mexico.', 'dad', 4, 6) AS res;
结果:
┌─res───────────────────┐
│ My dad is from Mexico.│
└───────────────────────┘
2. overlayUTF8
将字符串 input
中的一部分替换为另一个字符串 replace
,从基于 1 的索引 offset
开始。
假设字符串包含有