当前位置:网站首页>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;边栏推荐
- Practical application of information security
- Stimulsoft Reports报告工具,Stimulsoft创建和构建报告
- 如何拒绝期末复习无用功?猿辅导:找准适合自己的复习方法很重要
- ML:置信区间的简介(精密度/准确度/精确度的三者区别及其关系)、使用方法、案例应用之详细攻略
- Developers, why does the maturity of container technology herald the arrival of cloud native era?
- 解决choice金融终端Excel/Wps插件修复visual basic异常
- In depth analysis of a large number of clos on the server_ The root of wait
- 在线文本数字识别列表求和工具
- [Simulation Proteus] détection de port 8 bits 8 touches indépendantes
- numpy的索引和图片的索引一样吗?
猜你喜欢

Exercise "product": self made colorful Prompt string display tool (for loop and if condition judgment)

Analysis of IM instant messaging development technology on modern web

岁月不饶人

Wechat applet - requestsubscribemessage:fail can only be invoked by user tap gesture

外包干了三年,废的一踏糊涂...

In depth analysis of a large number of clos on the server_ The root of wait

Interviewer: how to solve the problem of massive requests for data that does not exist in redis, which affects the database?
![[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

清洁、对话、带娃,扫地机摆脱“人工智障”标签

Solve the problem of repairing Visual Basic exceptions with excel/wps plug-in of choice financial terminal
随机推荐
Time flies that year
Vant weave - remove (clear) < van button > button component Click to display gray background effect
一些生活的思考
外包干了三年,废的一踏糊涂...
[Simulation Proteus] détection de port 8 bits 8 touches indépendantes
网易云音乐内测音乐社交 App“MUS”,通过音乐匹配同频朋友
[concurrent programming] if you use channel to solve concurrency problems?
2022年最新最详细IDEA关联数据库方式、在IDEA中进行数据库的可视化操作(包含图解过程)
Shell spec date format
2020-12-03
眼底出血术后需注意事项//每天必看
Analysis of IM instant messaging development technology on modern web
HC32M0+ GPIO
降低打新的预期
测试用例设计方法之等价类划分方法
A Si's mood swings
What are the top ten securities companies? In addition, is it safe to open a mobile account?
Live broadcast configuration of crmeb knowledge payment system program configuration (method 2)
In 2022, the latest and most detailed idea associated database method and visual operation of database in idea (including graphic process)
Unity编辑器随机生成物体,更换场景之后物体丢失问题解决