当前位置:网站首页>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;

边栏推荐
- First day of learning C language
- IDC报告:腾讯云数据库稳居关系型数据库市场TOP 2!
- 关于mysql中的json解析函数JSON_EXTRACT
- 【性能测试】jmeter+Grafana+influxdb部署实战
- The first lesson of EasyX learning
- Function sub file writing
- Thoughtworks 全球CTO:按需求构建架构,过度工程只会“劳民伤财”
- BigDecimal除法的精度问题
- 33: Chapter 3: develop pass service: 16: use redis to cache user information; (to reduce the pressure on the database)
- 项目引入jar从私服Nexus 拉去遇到的一个问题
猜你喜欢

哈趣K1和哈趣H1哪个性价比更高?谁更值得入手?

The survey shows that the failure rate of traditional data security tools in the face of blackmail software attacks is as high as 60%

High number | summary of calculation methods of volume of rotating body, double integral calculation of volume of rotating body

基于51单片机的电子时钟设计

兰空图床苹果快捷指令

URP下Alpha从Gamma空间到Linner空间转换(二)——多Alpha贴图叠加

CVPR 2022最佳学生论文:单张图像估计物体在3D空间中的位姿估计

Use JDBC technology and MySQL database management system to realize the function of course management, including adding, modifying, querying and deleting course information.
Learn about MySQL transaction isolation level

Use of ThinkPHP template
随机推荐
CMake教程Step5(添加系统自检)
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
EasyX second lesson
flask解决CORS ERR 问题
漫画:有趣的海盗问题 (完整版)
thinkphp3.2.3
[first lecture on robot coordinate system]
VBA驱动SAP GUI实现办公自动化(二):判断元素是否存在
【性能测试】jmeter+Grafana+influxdb部署实战
[binary tree] insufficient nodes on the root to leaf path
Matery主题自定义(一)黑夜模式
First day of learning C language
Example tutorial of SQL deduplication
一口气读懂 IT发展史
Flow characteristics of kitchen knife, ant sword, ice scorpion and Godzilla
兰空图床苹果快捷指令
[Jianzhi offer] 62 The last remaining number in the circle
How to write a full score project document | acquisition technology
SQL删除重复数据的实例教程
Complete solution instance of Oracle shrink table space