6.6、字符串操作函数
这里写目录标题
-
-
- 6.6、字符串操作函数
-
- 字符串拼接
- 查找字符串第一次出现位置
- 字符串大小写转换
- 字符串截取
btrim(string a)
trim(string a)
btrim(string a,string chars_to_trim)
ltrim(string a)
rtrim(string a)
char_length(string a)
character_length(string a)
length(string a)
字符串拼接
concat(string a,string b…)
concat_ws(string sep,string a,string b…)
select concat_ws('-','hello','world') as concat_ws;
查找字符串第一次出现位置
find_in_set(string str,string strList)
select find_in_set('c','a,b,c,d,e,f,g') as find_in_set;
instr(string str,string substr)
select instr('abcdefg','bcd') as instr;
locate(string substr,string str,[int pos])
> select locate('bc','abcdefgabc',3) as locate;
字符串大小写转换
initcap(string str)
lower(string a)
lcase(string a)
upper(string a)
ucase(string a)
字符串截取
regexp_extract(string subject,string pattern,int index)
+
| regexp_extract('abcdef123ghi456jkl', '.*?(\\d+)', 0) |
+
| abcdef123ghi456 |
+
regexp_like(string source,string pattern,[string options])
options参数:
- c: 区分大小写匹配(默认)
- i:不区分大小写
- m:多行匹配
- n:换行符匹配
+
| regexp_like('foo', 'f', 'i') |
+
| true |
+
regexp_replace(string initial,string pattern,string replacement)
+
| regexp_replace('aaabbbaaa', 'b+', 'xyz') |
+
| aaaxyzaaa |
+
split_part(string source,string delimiter,bigint n)
+
| split_part('x,y,z', ',', 1) |
+
| x |
+
repeat(string str,int n)
reverse(string a)
space(int n)
strleft(string a,int num_chars)
strright(string a,int num_chars)
substr(string a,int start,[int len])
substring(string a,int start,[int len])
translate(string input,string from,string to)
[master:21000] > select translate('hello world','world','cauchy') as translate;
+
| translate |
+
| hecca cauch |
+