常见函数
1.字符函数 length 获取参数值的字节个数
select length("zhangsan") as 结果;//8
select length("zhangsan ") as 结果;//9
2.拼接字符串 concat
select concat(last_name," ",first_name) as 姓名 from employees
3.upper转大写 lower转小写
select upper("lisi") as 结果; //LISI
select lower("WANGWU") as 结果;//wangwu
将姓变大写,名变小写,再拼接
select concat(upper(last_name)," ",lower(first_name)) as 姓名 from employees
4.字符串截取 substr,substring
索引从1开始, 从指定索引处开始截取
select substr("zhaoliu",5) as 结果;//liu
截取从指定索引处指定字符长度的字符
select substring("mingtian",3,3) as 结果;//ngt
姓中首字符大写,其他字母小写,用_拼接
select concat(upper(substr(last_name,1,1)),"_",lower(substr(last_name,2))) as 结果 from employees;
5.instr 返回子串第一次出现的索引,如果找不到返回0
select instr("zhangsan","an") as 结果;//3
6.trim 去除空白字符
select length(trim(" zhangsan ")) as 结果;
04_MySql数据查询语言DQL之常见函数
最新推荐文章于 2024-10-30 22:57:10 发布
本文详细介绍了MySQL中的数据查询语言DQL,重点讲解了在查询操作中常用的函数,包括聚合函数如SUM、AVG、MAX、MIN以及COUNT,还有字符串处理函数、日期时间函数等,帮助读者深入理解并有效运用这些函数进行数据查询。
摘要由CSDN通过智能技术生成