当前位置:网站首页>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;
边栏推荐
- 世界上最难的5种编程语言
- Wechat official account web page authorization login is so simple
- 网上办理期货开户安全吗?网上会不会骗子比较多?感觉不太靠谱?
- 漫画:寻找股票买入卖出的最佳时机
- 【二叉树】根到叶路径上的不足节点
- 深入理解Redis内存淘汰策略
- Understand the usage of functions and methods in go language
- 项目引入jar从私服Nexus 拉去遇到的一个问题
- Learn about MySQL transaction isolation level
- Detailed explanation of printf() and scanf() functions of C language
猜你喜欢
随机推荐
Understand the usage of functions and methods in go language
thinkphp模板的使用
ICML 2022 | Meta提出鲁棒的多目标贝叶斯优化方法,有效应对输入噪声
Practical example of propeller easydl: automatic scratch recognition of industrial parts
【二叉树】根到叶路径上的不足节点
[Jianzhi offer] 66 Build product array
winedt常用快捷键 修改快捷键latex编译按钮
Judge whether a string is a full letter sentence
Detailed explanation of printf() and scanf() functions of C language
Embedded UC (UNIX System Advanced Programming) -3
Flask solves the problem of CORS err
Embedded-c Language-4
Error in compiling libssh2. OpenSSL cannot be found
What else do you not know about new map()
机器学习02:模型评估
easyNmon使用汇总
叩富网开期货账户安全可靠吗?怎么分辨平台是否安全?
mysql中取出json字段的小技巧
项目引入jar从私服Nexus 拉去遇到的一个问题
[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