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

边栏推荐
- Using C language to realize palindrome number
- easyNmon使用汇总
- 7.Scala类
- Use byte stream to read Chinese from file to console display
- ClickHouse(03)ClickHouse怎么安装和部署
- 33: Chapter 3: develop pass service: 16: use redis to cache user information; (to reduce the pressure on the database)
- Embedded UC (UNIX System Advanced Programming) -3
- Zhang Ping'an: accélérer l'innovation numérique dans le cloud et construire conjointement un écosystème industriel intelligent
- flask解决CORS ERR 问题
- MySQL之知识点(七)
猜你喜欢
Summary of optimization scheme for implementing delay queue based on redis

Error in composer installation: no composer lock file present.
一文了解MySQL事务隔离级别

Rider set the highlighted side of the selected word, remove the warning and suggest highlighting

【性能测试】jmeter+Grafana+influxdb部署实战

VBA驱动SAP GUI实现办公自动化(二):判断元素是否存在

腾讯音乐上线新产品“曲易买”,提供音乐商用版权授权

Machine learning 02: model evaluation

Three traversal methods of binary tree
In depth understanding of redis memory obsolescence strategy
随机推荐
Redis+caffeine two-level cache enables smooth access speed
Cmake tutorial step6 (add custom commands and generate files)
EasyX second lesson
哈趣K1和哈趣H1哪个性价比更高?谁更值得入手?
Domain name resolution, reverse domain name resolution nbtstat
Zhang Ping'an: accélérer l'innovation numérique dans le cloud et construire conjointement un écosystème industriel intelligent
flask解决CORS ERR 问题
Is it safe and reliable to open futures accounts on koufu.com? How to distinguish whether the platform is safe?
Winedt common shortcut key modify shortcut key latex compile button
忽米沄析:工业互联网标识解析与企业信息系统的融合应用
北京内推 | 微软亚洲研究院机器学习组招聘NLP/语音合成等方向全职研究员
Is it safe for qiniu business school to open a stock account? Is it reliable?
MySQL queries the latest qualified data rows
CMake教程Step3(添加库的使用要求)
2022 年 Q2 加密市场投融资报告:GameFi 成为投资关键词
ternary operator
張平安:加快雲上數字創新,共建產業智慧生態
VBA驱动SAP GUI实现办公自动化(二):判断元素是否存在
Debug kernel code through proc interface
Error in compiling libssh2. OpenSSL cannot be found