当前位置:网站首页>MySQL function
MySQL function
2022-06-30 01:04:00 【Hua Weiyun】
function
- String function
- Numerical function
- Date function
- Flow function
String function
Common functions :
| function | function |
|---|---|
| CONCAT(s1, s2, …, sn) | String splicing , take s1, s2, …, sn Concatenate into a string |
| LOWER(str) | Convert all strings to lowercase |
| UPPER(str) | Convert all strings to uppercase |
| LPAD(str, n, pad) | padding-left , Use string pad Yes str Fill the left side of the , achieve n String length |
| RPAD(str, n, pad) | Right fill , Use string pad Yes str Fill the right side of the , achieve n String length |
| TRIM(str) | Remove the spaces at the beginning and end of the string |
| SUBSTRING(str, start, len) | Return from string str from start It's from the position len A string of length |
Examples of use :
-- Splicing SELECT CONCAT('Hello', 'World');-- A lowercase letter SELECT LOWER('Hello');-- Capitalization SELECT UPPER('Hello');-- padding-left SELECT LPAD('01', 5, '-');-- Right fill SELECT RPAD('01', 5, '-');-- Remove the space SELECT TRIM(' Hello World ');-- section ( The starting index is 1)SELECT SUBSTRING('Hello World', 1, 5);Numerical function
Common function :
| function | function |
|---|---|
| CEIL(x) | Rounding up |
| FLOOR(x) | Rounding down |
| MOD(x, y) | return x/y The mold |
| RAND() | return 0~1 The random number in |
| ROUND(x, y) | Find parameters x Round the value of , Retain y Decimal place |
Date function
Common functions :
| function | function |
|---|---|
| CURDATE() | Return current date |
| CURTIME() | Return current time |
| NOW() | Returns the current date and time |
| YEAR(date) | Get specified date A year of |
| MONTH(date) | Get specified date Month of |
| DAY(date) | Get specified date Date |
| DATE_ADD(date, INTERVAL expr type) | Return a date / Time value plus a time interval expr Time value after |
| DATEDIFF(date1, date2) | Return to start time date1 And end time date2 Days between |
Example :
-- DATE_ADDSELECT DATE_ADD(NOW(), INTERVAL 70 YEAR);Flow function
Common functions :
| function | function |
|---|---|
| IF(value, t, f) | If value by true, Then return to t, Otherwise return to f |
| IFNULL(value1, value2) | If value1 Not empty , return value1, Otherwise return to value2 |
| CASE WHEN [ val1 ] THEN [ res1 ] … ELSE [ default ] END | If val1 by true, return res1,… Otherwise return to default The default value is |
| CASE [ expr ] WHEN [ val1 ] THEN [ res1 ] … ELSE [ default ] END | If expr The value is equal to the val1, return res1,… Otherwise return to default The default value is |
Example :
select name, (case when age > 30 then ' middle-aged ' else ' youth ' end)from employee;select name, (case workaddress when ' The Beijing municipal ' then ' first-tier cities ' when ' Shanghai ' then ' first-tier cities ' else ' Second-tier cities ' end) as ' Work address 'from employee;边栏推荐
- Comparison between strings localecompare
- 存储引擎分析
- [cloud native] kernel security in container scenario
- 如何查看一个文件夹下所有文件的大小?
- 面试官:大量请求 Redis 不存在的数据,从而影响数据库,该如何解决?
- 【Proteus仿真】8比特端口檢測8獨立按鍵
- [proteus simulation] 8-bit port detection 8 independent keys
- Experience of C language course design: open source sharing of "push box" course design works
- 岁月匆匆那年
- How to view the size of all files in a folder?
猜你喜欢

干外包3年,真废了...

Online sql to CSV tool

作文总写不好怎么办?猿辅导:家长要注意这几点

UDP servers and clients in go

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

如何在IDEA中自定义模板、快速生成完整的代码?

Interviewer: how to solve the problem of massive requests for data that does not exist in redis, which affects the database?

Solve the problem of repairing Visual Basic exceptions with excel/wps plug-in of choice financial terminal

Text classification using huggingface

2022 6 月25 日交易总结
随机推荐
Seata 與三大平臺攜手編程之夏,百萬獎金等你來拿
[three.js] Web3D first experience
If the amount exceeds 6 digits after the decimal point, only 6 digits will be reserved, and if it is less than 6 digits, it will remain the same - Basic accumulation
字节面试惨遭滑铁卢:一面就被吊打,幸得华为内推,三面拿到offer
Outsourcing work for three years, waste a step confused
[recommended] how to quickly locate a bug during testing
The unity editor randomly generates objects. After changing the scene, the problem of object loss is solved
UDP servers and clients in go
HC32M0+ GPIO
测试用例设计方法之等价类划分方法
Go out and protect yourself
Nested call and chained access of functions in handwritten C language
Seata 与三大平台携手编程之夏,百万奖金等你来拿
[lorawan node application] the application and power consumption of Anxin ra-08/ra-08h module in lorawan network
Quick pow: how to quickly find power
Solving plane stress problem with MATLAB
利用tsne将不同句子关于相似度可视化出来
Online text digit recognition list summation tool
Good test / development programmers vs. average programmers
Crmeb SMS for program configuration of knowledge payment system