当前位置:网站首页>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;边栏推荐
- Equivalence class partition method for test case design method
- Yunna | fixed assets system management, NC system management where are the fixed assets
- xshell中怎么切换到root用户
- 出门在外保护好自己
- Go 中的 UDP 服务器和客户端
- [recommended] how to quickly locate a bug during testing
- 【Proteus仿真】8比特端口檢測8獨立按鍵
- 利用huggingface进行文本分类
- PHP wechat merchant transfer to change initiating merchant transfer API
- 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
猜你喜欢

In 2022, the latest and most detailed idea associated database method and visual operation of database in idea (including graphic process)

Solving plane stress problem with MATLAB

MySQL installation steps (detailed)

Nested call and chained access of functions in handwritten C language

CSV文件格式——方便好用个头最小的数据传递方式

The SQL statement concat cannot find the result

Good test / development programmers vs. average programmers

How did the data center change from "Britney Spears" to "Mrs. bull"?
![[qnx hypervisor 2.2 user manual]6.2.2 communication between guest and host](/img/a4/a84f916d3aa2cc59f5b686cd32797a.png)
[qnx hypervisor 2.2 user manual]6.2.2 communication between guest and host

传统微服务框架如何无缝过渡到服务网格 ASM
随机推荐
Crmeb SMS for program configuration of knowledge payment system
Quick pow: how to quickly find power
Comment personnaliser les modèles et générer rapidement le code complet dans l'idée?
太卷了~ 八股文,面试最强王者!
字节面试惨遭滑铁卢:一面就被吊打,幸得华为内推,三面拿到offer
[mrctf2020]ezpop-1 | PHP serialization
岁月匆匆那年
阿四的情绪波动
81. 搜索旋转排序数组 II
UDP servers and clients in go
[recommended] how to quickly locate a bug during testing
字符串之间的比较之 localeCompare
Outsourcing for 3 years is a waste
[concurrent programming] if you use channel to solve concurrency problems?
利用huggingface进行文本分类
[spark] basic Scala operations (continuous update)
[cloud native] kernel security in container scenario
How to refuse the useless final review? Ape tutoring: it is important to find a suitable review method
After the element uses align items center and overflow auto, some contents are not fully displayed
Top performance version 2 reading notes (IV) -- memory monitoring