当前位置:网站首页>[MySQL] left function | right function
[MySQL] left function | right function
2022-04-23 03:09:00 【When camellia flowers bloom.】
1.LEFT function
LEFT function Used to extract from a given string left Extract a specified number of characters
Grammatical structure
LEFT(str,len)
str: Given string , The character... Will be extracted from its left
len: Number of characters to extract , If this parameter is greater than the number of characters in the string , Then this function will return the actual string
Be careful : If any parameter is Null, The result returned to Null
Example
-- The result is empty.
SELECT LEFT('abcdefg',0);
-- abc
SELECT LEFT('abcdefg',3);
-- abcdefg
SELECT LEFT('abcdefg',10);
-- Null
SELECT LEFT('abcd',NULL);
-- LEFT Function can intercept numbers
-- 12
SELECT LEFT(123456,2);
2.RIGHT function
RIGHT function Used to extract from a given string On the right side Extract a specified number of characters
Grammatical structure
RIGHT(str,len)
str: Given string , The character... Will be extracted from its right
len: Number of characters to extract , If this parameter is greater than the number of characters in the string , Then this function will return the actual string
Be careful : If any parameter is Null, The result returned to Null
Example
-- The result is empty.
SELECT RIGHT('abcdefg',0);
-- efg
SELECT RIGHT('abcdefg',3);
-- abcdefg
SELECT RIGHT('abcdefg',10);
-- Null
SELECT RIGHT('abcd',NULL);
-- RIGHT Function can intercept numbers
-- 56
SELECT RIGHT(123456,2);
Practice cases
Import data
DROP TABLE IF EXISTS `employee_info`;
CREATE TABLE `employee_info` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) DEFAULT NULL,
`phone` varchar(255) DEFAULT NULL,
`salary` int(255) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8mb4;
INSERT INTO `employee_info` VALUES ('1', 'Odin', '13810809401', '10000');
INSERT INTO `employee_info` VALUES ('2', 'Kacky', '15820126789', '12000');
INSERT INTO `employee_info` VALUES ('3', 'Jerry', '15815810158', '11000');
INSERT INTO `employee_info` VALUES ('4', 'Harry', '15820176889', '13000');
INSERT INTO `employee_info` VALUES ('5', 'Sun', '13578945621', '9000');
employee_info surface

problem : Encrypt the employee's mobile phone number ( for example :138****9401) , By salary ascending order name,phone,salary Format output data
SELECT name, CONCAT(LEFT(phone,3),'****',RIGHT(phone,4))AS phone, salary
FROM employee_info
ORDER BY salary ASC;
Result display :

版权声明
本文为[When camellia flowers bloom.]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230309010538.html
边栏推荐
- 一套关于 内存对齐 的C#面试题,做错的人很多!
- How does Microsoft solve the problem of multiple programs on PC side -- internal implementation
- c#语法糖模式匹配【switch 表达式】
- Systemctl start Prometheus + grafana environment
- 基于.NetCore开发博客项目 StarBlog - (1) 为什么需要自己写一个博客?
- Small companies don't make formal offers
- 微软是如何解决 PC 端程序多开问题的——内部实现
- ASP. Net 6 middleware series - conditional Middleware
- 在.NE6 WebApi中使用分布式缓存Redis
- C syntax pattern matching [switch expression]
猜你喜欢

Source code interpretation of Flink index parameters (read quantity, sent quantity, sent bytes, received bytes, etc.)

2022A特种设备相关管理(电梯)上岗证题库及模拟考试

【新版发布】ComponentOne 新增 .NET 6 和 Blazor 平台控件支持

Impact of AOT and single file release on program performance

MYSQL05_ Ordr by sorting, limit grouping, group by grouping

微软是如何解决 PC 端程序多开问题的——内部实现

Aspnetcore configuration multi environment log4net configuration file

What kind of experience is it to prepare for a month to participate in ACM?

Xamarin effect Chapter 22 recording effect

Thoughts on the 2022 national network security competition of the national secondary vocational group (only one idea for myself) - network security competition questions (8)
随机推荐
TP5 multi conditional where query (using PHP variables)
Yes Redis using distributed cache in NE6 webapi
交换二叉树中每个结点的左和右
MYSQL04_ Exercises corresponding to arithmetic, logic, bit, operator and operator
Source code interpretation of Flink index parameters (read quantity, sent quantity, sent bytes, received bytes, etc.)
C# 11 的这个新特性,我愿称之最强!
. net tip: talk about the problem that the scoped service cannot be obtained in the middleware structure
C#中元组对象Tuple的使用
Blazor University (12)组件 — 组件生命周期
ASP. Net 6 middleware series - conditional Middleware
C# 读写二进制文件
OLED multi-level menu record
Find the number of leaf nodes of binary tree
Thoughts on the 2022 national network security competition of the national secondary vocational group (only one idea for myself) - network security competition questions (9)
Two methods are used to solve the "maximum palindrome product" problem
Recursion - outputs continuously increasing numbers
Opencv combines multiple pictures into video
Development notes of raspberry pie (12): start Advantech industrial control raspberry pie uno-220 Kit (I): introduction and operation of the system
中后二叉建树
Mise en service PID du moteur de codage (anneau de vitesse | anneau de position | suivant)