Skip to content

Text 函数和运算符

该部分函数和运算符用于操作 STRING/TEXT 类型的值。

签名 描述 示例
replace(string, source, target) 将 string 中出现的任何 source 替换为 target replace('hello', 'l', '-') -> 'he--o'
substring(string, start, length) 从 string 提取自 start 开始的长度为 length 的子字符串 substring('Hello', 2, 2) -> 'el'
left(string, length) 从 string 的左侧提取长度为 length 的子字符串 left('Hello', 4) -> 'Hell'
right(string, length) 从 string 的右侧提取长度为 length 的子字符串 left('Hello', 4) -> 'Hell'
trim(string, characters) 从 string 的两侧删除位于 characters 中的字符,如果没有指定 characters 则删除空白符 trim('>>>>><>test>><>', '<>') -> 'test'
string_split(string, separator) 使用分隔符 separator 来拆分 string string_split('hello world', ' ') -> ['hello', 'world']
string_split_regex(string, regex) 使用正则表达式 regex 来拆分 string string_split_regex('hello world; 42', ';? ') -> ['hello', 'world', '42']

Tips

在 SQL 中关于索引的都是基于 1 的索引,例如 substring 函数中的 start 参数 1 表示首字母

参考