当前位置:网站首页>MySql函数
MySql函数
2022-06-30 01:02:00 【华为云】
函数
- 字符串函数
- 数值函数
- 日期函数
- 流程函数
字符串函数
常用函数:
| 函数 | 功能 |
|---|---|
| CONCAT(s1, s2, …, sn) | 字符串拼接,将s1, s2, …, sn拼接成一个字符串 |
| LOWER(str) | 将字符串全部转为小写 |
| UPPER(str) | 将字符串全部转为大写 |
| LPAD(str, n, pad) | 左填充,用字符串pad对str的左边进行填充,达到n个字符串长度 |
| RPAD(str, n, pad) | 右填充,用字符串pad对str的右边进行填充,达到n个字符串长度 |
| TRIM(str) | 去掉字符串头部和尾部的空格 |
| SUBSTRING(str, start, len) | 返回从字符串str从start位置起的len个长度的字符串 |
使用示例:
-- 拼接SELECT CONCAT('Hello', 'World');-- 小写SELECT LOWER('Hello');-- 大写SELECT UPPER('Hello');-- 左填充SELECT LPAD('01', 5, '-');-- 右填充SELECT RPAD('01', 5, '-');-- 去除空格SELECT TRIM(' Hello World ');-- 切片(起始索引为1)SELECT SUBSTRING('Hello World', 1, 5);数值函数
常见函数:
| 函数 | 功能 |
|---|---|
| CEIL(x) | 向上取整 |
| FLOOR(x) | 向下取整 |
| MOD(x, y) | 返回x/y的模 |
| RAND() | 返回0~1内的随机数 |
| ROUND(x, y) | 求参数x的四舍五入值,保留y位小数 |
日期函数
常用函数:
| 函数 | 功能 |
|---|---|
| CURDATE() | 返回当前日期 |
| CURTIME() | 返回当前时间 |
| NOW() | 返回当前日期和时间 |
| YEAR(date) | 获取指定date的年份 |
| MONTH(date) | 获取指定date的月份 |
| DAY(date) | 获取指定date的日期 |
| DATE_ADD(date, INTERVAL expr type) | 返回一个日期/时间值加上一个时间间隔expr后的时间值 |
| DATEDIFF(date1, date2) | 返回起始时间date1和结束时间date2之间的天数 |
例子:
-- DATE_ADDSELECT DATE_ADD(NOW(), INTERVAL 70 YEAR);流程函数
常用函数:
| 函数 | 功能 |
|---|---|
| IF(value, t, f) | 如果value为true,则返回t,否则返回f |
| IFNULL(value1, value2) | 如果value1不为空,返回value1,否则返回value2 |
| CASE WHEN [ val1 ] THEN [ res1 ] … ELSE [ default ] END | 如果val1为true,返回res1,… 否则返回default默认值 |
| CASE [ expr ] WHEN [ val1 ] THEN [ res1 ] … ELSE [ default ] END | 如果expr的值等于val1,返回res1,… 否则返回default默认值 |
例子:
select name, (case when age > 30 then '中年' else '青年' end)from employee;select name, (case workaddress when '北京市' then '一线城市' when '上海市' then '一线城市' else '二线城市' end) as '工作地址'from employee;边栏推荐
- Yunna | how to use the system to manage fixed assets? How to manage fixed assets?
- Exercise "product": self made colorful Prompt string display tool (for loop and if condition judgment)
- Taguchi experimental method
- 2022年最新最详细IDEA关联数据库方式、在IDEA中进行数据库的可视化操作(包含图解过程)
- Common settings in idea
- How to refuse the useless final review? Ape tutoring: it is important to find a suitable review method
- 字节面试惨遭滑铁卢:一面就被吊打,幸得华为内推,三面拿到offer
- 字符串之间的比较之 localeCompare
- How latex enters a matrix
- What are the top ten securities companies? In addition, is it safe to open a mobile account?
猜你喜欢

如何在IDEA中创建Module、以及怎样在IDEA中删除Module?

太卷了~ 八股文,面试最强王者!

Go 中的 UDP 服务器和客户端

字节面试惨遭滑铁卢:一面就被吊打,幸得华为内推,三面拿到offer

How to switch to root in xshell

Netease cloud music beta music social app "mus" matches friends of the same frequency through music

Bytek suffered a disastrous defeat in the interview: he was hanged on one side, but fortunately Huawei pushed him in, and he got an offer on three sides

Clean, talk, bring children, and get rid of the label of "artificial mental retardation" for the sweeper

利用tsne将不同句子关于相似度可视化出来

如何拒绝期末复习无用功?猿辅导:找准适合自己的复习方法很重要
随机推荐
The SQL statement concat cannot find the result
Birds in the corn field
2020-12-03
How much is the fixed asset management system and the price of the fixed asset management system
IDEA中的常用设置
A Si's mood swings
Comment personnaliser les modèles et générer rapidement le code complet dans l'idée?
2022年最新最详细IDEA关联数据库方式、在IDEA中进行数据库的可视化操作(包含图解过程)
Solve the problem of repairing Visual Basic exceptions with excel/wps plug-in of choice financial terminal
MySQL installation steps (detailed)
How to view the size of all files in a folder?
After the element uses align items center and overflow auto, some contents are not fully displayed
Solving plane stress problem with MATLAB
Developers, why does the maturity of container technology herald the arrival of cloud native era?
[Simulation Proteus] détection de port 8 bits 8 touches indépendantes
十大券商有哪些?另外,手机开户安全么?
出门在外保护好自己
Command line Basics
【Games101】Transformation
numpy的索引和图片的索引一样吗?