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

边栏推荐
- Embedded UC (UNIX System Advanced Programming) -3
- Judge whether a number is a prime number (prime number)
- The survey shows that the failure rate of traditional data security tools in the face of blackmail software attacks is as high as 60%
- C language to get program running time
- 張平安:加快雲上數字創新,共建產業智慧生態
- Flask solves the problem of CORS err
- 激动人心!2022开放原子全球开源峰会报名火热开启!
- Rider 设置选中单词侧边高亮,去除警告建议高亮
- Oracle缩表空间的完整解决实例
- Tips for extracting JSON fields from MySQL
猜你喜欢

Machine learning 01: Introduction

ICML 2022 | Meta提出鲁棒的多目标贝叶斯优化方法,有效应对输入噪声

Embedded UC (UNIX System Advanced Programming) -1

The second day of learning C language for Asian people

NPM installation

Judge whether a number is a prime number (prime number)
深入理解Redis内存淘汰策略
In depth understanding of redis memory obsolescence strategy
MySql 查询符合条件的最新数据行

Wsl2.0 installation
随机推荐
CMake教程Step6(添加自定义命令和生成文件)
漫画:如何实现大整数相乘?(上) 修订版
dried food! Semi supervised pre training dialogue model space
Deeply cultivate 5g, and smart core continues to promote 5g applications
Embedded-c Language-4
北京内推 | 微软亚洲研究院机器学习组招聘NLP/语音合成等方向全职研究员
Example tutorial of SQL deduplication
[7.7 live broadcast preview] the lecturer of "typical architecture of SaaS cloud native applications" teaches you to easily build cloud native SaaS applications. Once the problem is solved, Huawei's s
[binary tree] insufficient nodes on the root to leaf path
Judge whether a string is a full letter sentence
Using C language to realize palindrome number
Use of ThinkPHP template
这个17岁的黑客天才,破解了第一代iPhone!
Three traversal methods of binary tree
Embedded-c Language-2
Rider 设置选中单词侧边高亮,去除警告建议高亮
编译libssh2报错找不到openssl
MySQL之知识点(七)
Is it safe to open futures accounts online? Will there be more liars online? Doesn't feel very reliable?
URP下Alpha从Gamma空间到Linner空间转换(二)——多Alpha贴图叠加