MySQL--->常用函数

数值型函数:

 常用数值型函数:

  • round (x,y) 四舍五入。返回数值x带有y为小数结果的数值(四舍五入)
    • select round(条件)  from  表
  • floor(x)向下取整。返回x的向下取整的整数
    • select  floor (条件)  from  表
  • ceil(x)向上取整。返回x的向上取整的整数
    • select  ceil  (条件)  from  表
  • truncate(x,y)数值截取。返回数值x截取y为小数的结果(不四舍五入)
    • select  floor (条件,1)  from  表

字符串函数:

常用字符串函数:

  • concat(str1,str2,str3...)合并字符串。将多个字符串合并成一个字符串
    • select concat (列,列) from   表
  • upper(x) 用于将字母转成大写
    • 和更新语句结合使用 :update  表  set  ? = upper(?);
  • lower(x) 用于将字母转成小写
    • 和更新语句结合使用 :update  表  set  ? = lower(?);
  • reverse(x)用于将字符串翻转
    • 和更新语句结合使用:update  表  set  ?=reverse(?)  where 列 = ?;

时间日期函数:

 常用的时间日期函数:

  • curdate() 返回当前日期   ----只有年月日
  • now() 返回当前日期时间  ----显示当前的所有时间
  • year(date) 从日期中选择出年份
    • select  year(列)  from   表 ;
  • date_format(date,'%Y-%m-%d') 把日期格式调整成年-月-日的格式     y 只取年份的两位   时%h  分%i   秒%s
    • select  date_format(列,'%Y-%m-%d')  from   表 ;

流程控制函数:

 数据库类函数:

 插入一本加密的书籍:

  • insert into books(bname,author,price,quanitity)values(MD5('西游记'),'吴承恩',20,10)
原文地址:https://www.cnblogs.com/wyk1/p/13426872.html