常用函数
字符串函数
- contact函数
 
将传入的字符连接成一个字符串
- insert函数
 - lower函数和upper函数
 - left(str,x)返回str最左边x个字符
 - right(str,x)返回str最右边x个字符
 - ltrim(str)去除左边空格
 - rtrim(str)去除右边空格
 - trim(str)去除俩边空格
 - repeat(str,x)返回str重复x次的结果
 - replace(str,a,b)替换全部的a为b
 substring(str,x,y)返回字符串str中第x位置其y个字符长度的字符
数值函数
abs(x) 返回绝对值
- ceil(x) 小数不为零部分上取整,即向上取最近的整数,ceil(1.1); = 2
 - floor(x) 小数不为零部分下取整
 - mod(x,y) 返回x/y的模
 rand() 返回0-1内随机的值 取1-10的随机值:ceil(rand()*10);
日期函数
curdate() 返回当前日期,只包含年月日
- curtime() 返回当前日期,只包含时分秒
 - now() 返回当前日期,全部都包含
 - unix_timestamp 返回当前时间戳
 - from_unixtime(unixtime) 将一个时间戳转化为日期
 - week(date) 返回当前是一年中的第几周
 - year(date) 放回日期是哪一年
 - hour(date)
 - minute(date)
 - date_format(date,fmt) 将字符串格式化日期date值
 - date_add(date,interval expr type) 增加31年:select date_add(now(),interval 31 year);
 datediff(date1,date2) select datediff(‘2019-1-32’,now()) 计算2个日期相差天数
流程函数
if(value,’true’,’false’) 满足条件返回真,否则返回假
select if((select max(salary) from employees where name='李白')>5000,'经理','员工');

ifnull(value1,value2)
case when then end
select case when 2>3 then 'True' else 'False' end;
其它函数
database()
- version()
 - user() 返回当前用户
 - password()
 - md5()
 
