在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间的天数

相关文章:

  • 2021-12-30
  • 2021-07-29
  • 2022-01-06
  • 2022-03-07
  • 2022-12-23
  • 2022-01-10
  • 2022-02-16
  • 2022-12-23
猜你喜欢
  • 2021-09-13
  • 2022-01-26
  • 2021-06-28
  • 2022-01-14
  • 2021-12-20
  • 2022-01-05
  • 2023-03-12
相关资源
相似解决方案