最新文章
- MySQL中, group by 和 order by 一起使用会有排序问题,group by 和 order by 同时使用时要注意的地方
- Vue学习笔记(10) ——Vue组件中的data和methods
- Vue学习笔记(9) ——Vue组件创建的几种方式
- Vue学习笔记(8) ——Vue实例的生命周期
- Vue学习笔记(7) —— 过滤器 filter的基本使用
- Vue学习笔记(6) ——v-if指令和v-show指令
- Vue学习笔记(5) —— v-for指令和key属性
- Vue学习笔记(5) —— Vue中样式-class样式和style样式
- Vue学习笔记(4) —— v-model指令,双向数据绑定
- Vue学习笔记(3) —— Vue事件修饰符
关注我

在线咨询
x
有什么可以帮到你

点击咨询
MySQL 字符串函数 , MySQL 数学函数
- 分类:MySQL技术
- 时间:2020-06-09
- 共296人围观
简介MySQL 有很多内置的众多功能强大、方便易用的函数,使用这些函数,可以极大地提高用户对于数据库的管理效率,比如 字符串函数 , 数学函数, 时间函数 ...
一、MySQL字符串函数
1. 字符串连接 —— concat()
select concat('php','linux');
2. 转小写 —— lcase()
select lcase('PHP IS VERY MUCH!');
3. 转大写 —— ucase()
select id,ucase(username),age from user;
4. 长度 —— length()
select length('linux');
5. 取除左边的空格 —— ltrim()
select length(ltrim(' linux'));
6. 取除右边的空格 —— rtrim()
select length(rtrim('linux '));
7. 重复 —— repeat()
select concat(repeat('-',20),'linux');
8. 替换 —— replace()
select replace('linux and java','linux','php');
9. 截取 —— substring()
select substring('/usr/local/src',6,5);
10. 空格 —— space();
select concat('linux',space(20),'php');
二、MySQL数学函数
1. 十进制转2进制 —— bin()
select bin(10);
2. 取上一个整数 —— ceiling()
select ceiling(10.5);
3. 取下一个整数 —— floor()
select floor(10.5);
4. 取最大数 —— max()
select max(id) from user;
5. 取最小数 —— min()
select min(id) from user;
6. 开平方 —— sqrt()
select sqrt(100);
7. 求随机数 —— rand()
select * from user order by rand();
三、MySQL时间函数
1. 当前日期 —— curdate()
select curdate();
2. 当前时间 —— curtime()
select curtime();
3. 当前日期和时间 —— now()
select now();
4. 当前时间戳 —— unix_timestamp();
select unix_timestamp();
5. 时间戳转日期 —— from_unixtime()
select from_unixtime(1492176896)
6. 一年中的第几周 —— week(date)
select week('2017-1-8')
7. 日期中的年部分 —— year(date)
select year('2017-4-14');
8. 日期差值 —— datediff()
select datediff('2017-4-14','2017-4-10');
上一篇:MySQL正则表达式的使用
下一篇:MySQL 事务管理(ACID)