加入收藏 | 设为首页 | 会员中心 | 我要投稿 核心网 (https://www.hxwgxz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程 > 正文

自学MySql内置函数知识点归纳

发布时间:2022-03-18 16:52:23 所属栏目:编程 来源:互联网
导读:字符串函数 查看字符的ascii码值ascii(str),str是空串时返回0 select ascii(a); 查看ascii码值对应的字符char(数字) select char(97); 拼接字符串concat(str1,str2...) select concat(12,34,ab); 包含字符个数length(str) select length(abc); 截取字符串 l
      字符串函数
 
     查看字符的ascii码值ascii(str),str是空串时返回0
select ascii('a');
      查看ascii码值对应的字符char(数字)
select char(97);
     拼接字符串concat(str1,str2...)
select concat(12,34,'ab');
     包含字符个数length(str)
select length('abc');
     截取字符串
left(str,len)返回字符串str的左端len个字符
right(str,len)返回字符串str的右端len个字符
substring(str,pos,len)返回字符串str的位置pos起len个字符
select substring('abc123',2,3);
 
求x的y次幂pow(x,y)
select pow(2,3);
获取圆周率PI()
select PI();
随机数rand(),值为0-1.0的浮点数
select rand();
还有其它很多三角函数,使用时可以查询文档
日期时间函数
获取子值,语法如下
year(date)返回date的年份(范围在1000到9999)
month(date)返回date中的月份数值
day(date)返回date中的日期数值
hour(time)返回time的小时数(范围是0到23)
minute(time)返回time的分钟数(范围是0到59)
second(time)返回time的秒数(范围是0到59)
select year('2016-12-21');
日期计算,使用+-运算符,数字后面的关键字为year、month、day、hour、minute、second
select '2016-12-21'+interval 1 day;
日期格式化date_format(date,format),format参数可用的值如下
 
select date_format('2016-12-21','%Y %m %d');
当前日期current_date()
select current_date();
当前时间current_time()
select current_time();
当前日期时间now()
select now();
以上就是本次介绍的全部相关知识点。

(编辑:核心网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    热点阅读