当前位置:网站首页>MySQL内部函数介绍
MySQL内部函数介绍
2022-08-05 09:01:00 【1 + 1=王】
字符串函数
1. length(str)
计算字符串的长度。
select length('1+1=wang'),length('1+1=王');

2. concat(str1,str1,…)
合并字符串
select concat('1+1','=','王');

3. insert(str1,n,m,str2)
替换str1中从n开始的后m个字符为str2
select insert('1+1=wang',5,4,'王');

4. lower(str)
将字符串中的字母转化为小写。
select lower('WaNg');

5. upper(str)
将字符串中的字母转化为大写。
select upper('WaNg');

6. left(str,n)
截取左侧n个字符。
select left ('1+1=王',3);

7. right(str,n)
截取右侧n个字符。
select right('1+1=王',3);

8. trim(str)
删除字符串左右两侧的空格。
select trim(' 1+1=王 ');

9. substring(str,n,m)
截取从n后的m个字符。
select substring('1+1=wang',5,4);

10. reverse(str)
反转字符串。
select reverse('1+1=wang');

数学函数
- abs(num):求绝对值
- sqrt(num):开二次方根
- mod(num1,num2):求余数
- ceil(num):向上取整
- floor(num):向下取整
- rand():生成0~1的随机数
- round(num):四色五人
- sign(num):返回参数的符号,正数(1),负数(-1)
- pow(num1,num2):求num1num2
- sin(num):求正弦值
- cos(num):求余弦值
- tan(num):求正切值
- asin(num):求反正弦值
- acos(num):求反余弦值
- atan(num):求反正切值
- cot(num):求余切值
日期函数
current_date():获取当前日期值

current_time():获取当前时间

now():获取当前日期和时间

unix_timestamp():获取当前时间戳

from_unixtime(1659168184):将时间戳转换为时间格式

month(date):获取指定日期的月份

monthname(date):获取指定日期的月份的英文名称

dayname(date):获取指定日期对应的星期的英文名称

dayofweek(date):获取指定日期是一周的第几天(周日为1,周六为7)

week(date):计算指定日期是一年中的第几周

dayofyear(date):计算指定日期是一年中的第几天

dayofmonth(date):计算指定日期是一个月中的第几天

year(date):获取指定日期的年份

time_to_sec(date):将时间转换为秒

sec_to_time(58734):将秒转换为时间

adddate(date, days):向指定日期加days天

subdate(date, days):向指定日期减days天

addtime(date, seconds):向指定时间加seconds秒

subtime(date, seconds):向指定时间减seconds秒

datediff(date1, date2):计算两个日期的天数差,date1-date2

聚合函数
- max():查询指定列的最大值
select max(age) from user;
- min():查询指定列的最小值
select min(age) from user;
- count():统计查询结果的行数
select count(id) from user;
- sum():返回指定列的总和
select sum(age) from user;
- avg():返回指定列数据的平均值
select avg(age) from user;
系统信息函数
user(),session_user(),system_user(),current_user():获取用户信息

database():获取当前数据库名

version():获取数据库版本号

格式化函数
date_format(date, fmt):格式化日期

time_format(time, fmt):格式化时间

format(x, y):格式化数字,y为保留的小数位数

inet_aton(ip):获取ip的数字表示

inet_ntoa(num):获取num代表的ip地址
边栏推荐
- tear apart loneliness
- XCODE12 在使用模拟器(SIMULATOR)时编译错误的解决方法
- 网页直接访问链接不让安全中心拦截
- 宝塔实测-搭建中小型民宿酒店管理源码
- Controller-----controller
- 嵌入式实操----基于RT1170 移植memtester做SDRAM测试(二十五)
- Three solutions to solve cross-domain in egg framework
- SQL语句查询字段内重复内容,并按重复次数加序号
- selectPage 动态改变参数方法
- The Secrets of the Six-Year Team Leader | The Eight Most Important Soft Skills of Programmers
猜你喜欢

链表中的数字相加----链表专题

网页直接访问链接不让安全中心拦截

egg框架中解决跨域的三种方案

全面讲解GET 和 POST请求的本质区别是什么?原来我一直理解错了

Weekly Report 2022-8-4

mySQL数据库初始化失败,有谁可以指导一下吗

CCVR基于分类器校准缓解异构联邦学习

苹果官网商店新上架Mophie系列Powerstation Pro、GaN充电头等产品

周报2022-8-4

ECCV 2022 Oral Video Instance Segmentation New SOTA: SeqFormer & IDOL and CVPR 2022 Video Instance Segmentation Competition Champion Scheme...
随机推荐
love is a sad song
Assembly language (8) x86 inline assembly
ps怎么拼图,自学ps软件photoshop2022,PS制作拼图效果
tensorflow.keras无法引入layers
spark集群部署(第三弹)
ts/js function pass parameter with function writing
手机上流行的各类谜语
网页直接访问链接不让安全中心拦截
The color of life divine
【 a daily topic 】 1403. The increasing order of the sequence, boy
What is the connection and difference between software system testing and acceptance testing? Professional software testing solution recommendation
tensorflow.keras cannot introduce layers
程序员的七种武器
leetcode 剑指 Offer 10- I. 斐波那契数列
8.4 Summary of the mock competition
Undefined symbols for architecture arm64解决方案
在colab里怎样读取google drive数据
Neuron Newsletter 2022-07|新增非 A11 驱动、即将支持 OPC DA
XSS靶机通关以及XSS介绍
ps怎么替换颜色,自学ps软件photoshop2022,ps一张图片的一种颜色全部替换成另外一种颜色