您好,欢迎访问一九零五行业门户网

MySQL中字符串函数有哪些

字符串函数
1、返回字符串 s 的第一个字符的 ascii 码
select ascii('ab');---- 返回a的ascii码值:65
2、length/char_length(s)/character_length(s)返回字符串 s 的字符数
select length('1234');---- 返回4
3、concat(s1,s2…sn)字符串 s1,s2 等多个字符串合并为一个字符串
select concat('hel','llo');---- 返回hello
4、find_in_set(s1,s2)返回在字符串s2中与s1匹配的字符串的位置
select find_in_set("c", "a,b,c,d,e");---- 返回3
5、format(x,n)函数可以将数字 x 进行格式化 “#,###.##”, 将 x 保留到小数点后 n 位,最后一位四舍五入
select format(250500.5634, 2); ---- 返回250,500.56
6、insert(s1,x,len,s2)字符串 s2 替换 s1 的 x 位置开始长度为 len 的字符串
select insert("google.com", 1, 6, "runnob");---- 返回runoob.com
7、locate(s1,s)从字符串 s 中获取 s1 的开始位置
select locate('st','myteststring');---- 返回5
8、lcase(s)/lower(s)将字符串 s 的所有字母变成小写字母
select lower('runoob');---- 返回runoob
9、ucase(s)/upper(s)将字符串 s 的所有字母变成大写字母
select ucase('runoob');---- 返回runoob
10、trim(s)去掉字符串 s 开始和结尾处的空格
select trim(' runoob ');---- 返回runoob
11、ltrim(s)去掉字符串 s 开始处的空格
select ltrim(' runoob ');---- 返回 ’runoob ‘
12、rtrim(s)去掉字符串 s 结尾处的空格
select rtrim(' runoob ');---- 返回 ’ runoob‘
13、substr(s, start, length)从字符串 s 的 start 位置截取长度为 length 的子字符串
select substr("runoob", 2, 3) as extractstring;---- 从字符串 runoob 中的第 2 个位置截取 3个 字符,返回uno
14、substr/substring(s, start, length)从字符串 s 的 start 位置截取长度为 length 的子字符串
select substr/substring("runoob", 2, 3);---- 从字符串 runoob 中的第 2 个位置截取 3个 字符,返回uno
15、position(s1 in s)从字符串 s 中获取 s1 的开始位置
select position('b' in 'abc');---- 返回2
16、repeat(s,n)将字符串 s 重复 n 次
select repeat('runoob',3);---- 返回runoobrunoobrunoob
17、reverse(s)将字符串s的顺序反过来
select reverse('abc');---- 返回cba
18、strcmp(s1,s2)比较字符串 s1 和 s2,如果 s1 与 s2 相等返回 0 ,如果 s1>s2 返回 1,如果 s1<s2 返回 -1
select strcmp("runoob", "runoob");---- 返回0
以上就是mysql中字符串函数有哪些的详细内容。
其它类似信息

推荐信息