【MySQL复习】SQL函数
一、数学函数
1、求绝对值abs()
select abs(num) from tableName where ....
2、向下取整floor(),例如:99.9→99
select floor(num) from tableName where ...;
3、向上取整 ceil(),例如99.9→100
select ceil(num) from tableName where ...;
二、字符串函数
1、添加数据insert(目标字符串,下标,长度,追加内容)
select insert(name,2,3,hello) from tableName where ...;
解释:对查询结果从第二个字符,往后面截取3个字符,把这三个字符替换为hello
2、upper() 将全部字符串转化为大写
select upper(name) from tableName where ....;
3、lower() 将全部字符串转化为小写
select lower(name) from tableName where ....;
4、left() 截取字符:截取前三个字符
select left(name,3) from tableName where ...;
5、right() 从后面截取字符
6、substring(str,index,len) 截取中间字符
select substring(name,2,4) from tableName where ...;
7、reverse() 逆序输出字符串
select reverse(name) from tableName where ...;
本文来自博客园,作者:小李不背锅,转载请注明原文链接:https://www.cnblogs.com/lishilin-glut/p/15929636.html