一、字符函数:
length
:字符个数
select length('john');
concat
:拼接字符串
select concat('I',' ','like',' ','mysql');
upper/lower
:大小写转换
select upper('mysql');
select lower('MySQL');
substr/substring
:字符串截取
(
功能相同
)
-- 从第几个字符开始截取,注意:索引从1开始
select substr('I like MySQL',8);
-- 从第几个字符开始截取,截取几个字符
select substr('I like MySQL',8,2);
instr
:子串在字符串中的起始索引
select instr('I like MySQL','MySQL');
trim
:去掉前后空格
select trim(' My SQL ');
replace
:替换
select replace('aabb','bb','cc');
二、数学函数:
abs:
绝对值
select abs(-26);
round
:四舍五入
select round(1.4);
-- 小数点后保留几位
select round(1.567,2);
ceil
:向上取整
select ceil(1.2);
floor
:向下取整
select floor(1.2);
truncate
:截断
(
小数点后保留几位
)
select truncate(1.61,2);
mod
:取模
select mod(10,3);
三、日期时间 :
now
:返回当前系统时间
select now(); -- 包括日期和时间 1
curdate
:返回当前系统日期,不包含时间
select curdate();
curtime
:返回当前系统时间
select curtime();
获取指定的部分
select year('2020-10-10');
select month('2020-10-10');
str_to_date
:将日期格式的字符转换成指定格式的日期
select str_to_date('2020年10月12','%Y年%m月%d');