当前位置:网站首页>MySQL之知识点(六)
MySQL之知识点(六)
2022-07-05 16:57:00 【flag:卷王!】
一、数值函数
1,基本函数

演示效果:
代码:select abs(-12),sign(-23),sign(43),pi(),ceil(32.32),ceiling(-32.32),floor(43.43),floor(-43.43),mod(12,5) from dual;

四舍五入:
mysql> select round(123,456),round(123.456,0),round(123.456,1),round(123.456,-1) from dual;
截断操作:(无论是什么,都不要)
mysql> select truncate(123.456,0),truncate(123.456,1),truncate(129.45,-1) from dual;


2,三角函数

其中角度与弧度互换函数:
mysql> select radians(30),radians(45) from dual;
mysql> select degrees(2*pi()) from dual;(注意PI后面必须截有括号)

三角函数:
mysql> select sin(radians(30)),asin(0.5),degrees(asin(0.5)),tan(radians(45)) from dual;

3,指数与对数
对数:
mysql> select pow(2,5),power(2,4),exp(2) from dual;
指数(默认是e):
mysql> select ln(exp(2)),log(exp(2)),log10(10),log2(4) from dual;

4,进制间的转换

mysql> select bin(10),hex(10),oct(10),conv(10,10,8) from dual;

二、字符串函数

需要注意的是:
在字符串索引是从1开始的:
mysql> select insert('hellowworld',2,3,'aaaaa'),replace('helloword','l','mmm') from dual;

三、日期与时间函数
1,获取日期、时间的

获取日期与时间:
mysql> select curdate(),current_date(),curtime(),now(),sysdate(),utc_date(),utc_time() from dual;

2,日期与时间戳的转化

mysql> select unix_timestamp(),unix_timestamp('2022-7-04 12:12:30') from dual;

3,获取月份、星期、星期数、天数等函数

mysql> select year(curdate()),month(curdate()),day(curdate()),hour(curtime()),minute(now()),second(sysdate()) from dual;

4,日期的操作函数

mysql> select extract(second from now()),extract(month from now()) from dual;

5,时间与秒钟转换的函数

mysql> select time_to_sec(curtime()),sec_to_time(45880) from dual;

6,计算日期与时间的函数
第一组:

select now(), date_add(now(),interval 1 year), date_add(now(),interval -1 year),date_sub(now(),interval 1 year) from dual;

第二组:

5,日期的格式化和解析
格式化:日期---->字符串
解析:字符串---->日期



格式化(根据不同情况来确定大小写):
mysql> select date_format(curdate(),'%y-%m-%d'),date_format(now(),'%y-%m-%d') from dual;
mysql> select date_format(curdate(),'%Y-%m-%d'),date_format(now(),'%Y-%m-%d') from dual;

解析:(格式化的逆过程):
mysql> select str_to_date('2022-October-24th 11:34:42 Monday 1 ','%Y-%M-%D %h:%i:%S %W %w ') from dual;

边栏推荐
- 深入理解Redis内存淘汰策略
- CMake教程Step4(安装和测试)
- C#(Winform) 当前线程不在单线程单元中,因此无法实例化 ActiveX 控件
- ternary operator
- Use JDBC technology and MySQL database management system to realize the function of course management, including adding, modifying, querying and deleting course information.
- Is it safe for qiniu business school to open a stock account? Is it reliable?
- mysql中取出json字段的小技巧
- MySql 查询符合条件的最新数据行
- CVPR 2022最佳学生论文:单张图像估计物体在3D空间中的位姿估计
- 独立开发,不失为程序员的一条出路
猜你喜欢
![[first lecture on robot coordinate system]](/img/3c/af056f0fe68b3244a3dc491ceb291d.png)
[first lecture on robot coordinate system]

激动人心!2022开放原子全球开源峰会报名火热开启!

Embedded-c Language-1
Oracle缩表空间的完整解决实例

The first EMQ in China joined Amazon cloud technology's "startup acceleration - global partner network program"

Using C language to realize palindrome number

Error in composer installation: no composer lock file present.

thinkphp模板的使用

Browser rendering principle and rearrangement and redrawing

7.Scala类
随机推荐
Alpha conversion from gamma space to linner space under URP (II) -- multi alpha map superposition
域名解析,反向域名解析nbtstat
Read the basic grammar of C language in one article
easyNmon使用汇总
The first lesson of EasyX learning
漫画:有趣的【海盗】问题
ICML 2022 | Meta提出鲁棒的多目标贝叶斯优化方法,有效应对输入噪声
Embedded-c Language-1
Judge whether a string is a full letter sentence
这个17岁的黑客天才,破解了第一代iPhone!
goto Statement
Cloud security daily 220705: the red hat PHP interpreter has found a vulnerability of executing arbitrary code, which needs to be upgraded as soon as possible
Use of ThinkPHP template
Machine learning 02: model evaluation
Is it safe for qiniu business school to open a stock account? Is it reliable?
项目引入jar从私服Nexus 拉去遇到的一个问题
高数 | 旋转体体积计算方法汇总、二重积分计算旋转体体积
Error in composer installation: no composer lock file present.
The first EMQ in China joined Amazon cloud technology's "startup acceleration - global partner network program"
张平安:加快云上数字创新,共建产业智慧生态