mysql 函数

数值函数

ceil(x): 返回大于x的最小整数值                select    ceil(28.5);        结果:29

floor(x):返回小于x的最小整数值                    select    floor(28.5);       结果:28

round(x):四舍五入                                    

round (x,y) 对x四舍五入,保留y位小数                select    round(28.55,1);        结果:28.6

truncate(x,y) 截断函数,不四舍五入                    select    truncate(28.55,1);    结果:28.5

mod(x): 取余函数                select    mod(11,2);        结果:1

字符函数

concat(s1,s2,..):链接函数                    select    concat('hello','world');    结果:helloworld

concat_ws(x,s1,s2,...):分割函数                select    concat_ws('-','hello','world');    结果:hello-world

lower(str):大写字母转换为小写字母                select    lower('HELLO');    结果:hello

upper(str):小转大

length(str): 返回字符串长度                    select    length('hello');    结果:5

ltrim(s):删除字符串左侧空格                   

rtrim(s):删除字符串右侧空格

substring(s,n,len):截取字符串                  select    substring('hellokkkk',1,5);    结果:hello

 left(str,n):左截取字符串                            select    left('hello',2);    结果:he

right(str,n):右截取字符串 

replace(str,a,b):替换函数                        select    replace('hello world','world','mysql');    结果:hello mysql

 format(x,n):将数字转换为字符串 并保留n位小数    select    format(123.456,2);        结果:123.46

日期时间函数

curdate()            select    curdate();       结果:2018-4-12

curtime()            select    curtime();       结果:21:15:30

now()                  select    now();            结果:2018-4-12  21:15:30

select    date_add('2018-4-12',interval 5 month);    结果:2018-9-12

聚合函数

avg()            求某列的平均数

count()        求某列的行数

max()           求某列的最大数

min()           求某列的最小数

sum()           求某列值的和

信息函数与加密函数

version()        返回当前mysql服务器版本的版本号

connection_id()                返回mysql服务器当前连接的次数,每个连接都有各自唯一的id

database()和schema()                返回当前数据库名

user()                获取用户名的函数,返回当前登录用户的用户名

md5(str)    信息摘要算法,函数可以加密字符串 ,加密后的32位十六进制数字的二进制字符串形式返回,若参数为null,返回

                                                                                                                                                                                      null

password(str)    密码算法,从原明文密码str计算并返回加密后的密码字符串,当参数是null是,返回null


 


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值