mysql常见内置函数

在mysql中有许多内置的函数,虽然功能都能在PHP代码中实现,但巧妙的应用mysql内置函数可以大大的简化开发过程,提高效率。

在这里我总结一下一些常用的,方便以后查看:

mysql字符串函数:

concat(String2 [,...])         //连接字串

lcase(string2)           //转换成小写

ucase(string2)           //转换成大写

length(string)           //string长度

ltrim(string2)           //去除前端空格

rtrim(string2)           //去除后端空格

repeat(string2,count)       //重复count次

replace(str,search_str,replace_str)   //在str中用replace_str替换search_str

substring(str,position [,length])   //position开始,取length个字符,注意:position偏移量是从1开始的

space(count)           //生成count个空格

 


mysql数学函数:

bin(decimal_number) //十进制数字转换成二进制

ceiling(number2) //向上取整

floor(number2) //向下取整

max(列名) //最大值

min(列名) //最小值

sqrt(number) //平方根

rand() //随机数(0-1),可以进行随机排序:select * from user order by rand();

 


mysql日期函数:

curdate() // 返回当前日期

curtime() //返回当前时间

now() //返回当前的日期时间

unix_timestamp(date) //返回当前date的unix时间戳

from_unixtime(时间戳) //返回UNIX时间戳的日期值

week(date) //返回日期date为一年中的第几周

year(date) //返回日期date的年份

datediff(expr,expr2) //返回起始时间expr和结束时间expr2间的天数

posted @ 2019-07-31 15:55  独孤靖云  阅读(669)  评论(0编辑  收藏  举报