当前位置:网站首页>[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
边栏推荐
- The backtracking of stack is used to solve the problem of "the longest absolute path of file"
- 全网最全,接口自动化测试怎么做的?精通接口自动化测试详解
- 编码电机PID调试(速度环|位置环|跟随)
- Simple example of using redis in PHP
- PID debugging of coding motor (speed loop | position loop | follow)
- OLED多级菜单记录
- TP5 email (2020-05-27)
- ASP. Net 6 middleware series - Custom middleware classes
- 【无标题】
- 基于.NetCore开发博客项目 StarBlog - (1) 为什么需要自己写一个博客?
猜你喜欢

This new feature of C 11, I would like to call it the strongest!

xutils3修改了我提报的一个bug,开心

Laravel new route file

C language to achieve address book - (static version)

The most detailed in the whole network, software testing measurement, how to optimize software testing cost and improve efficiency --- hot

Blazor University (12)组件 — 组件生命周期

Small companies don't make formal offers

Detailed log display of openfeign call

樹莓派開發筆記(十二):入手研華ADVANTECH工控樹莓派UNO-220套件(一):介紹和運行系統

Yes Redis using distributed cache in NE6 webapi
随机推荐
Fight leetcode again (290. Word law)
使用栈来解决”迷你语法分析器“的问题
Openfeign details show
Thoughts on the 2022 national network security competition of the national secondary vocational group (only one idea for myself) - network security competition questions (8)
The most detailed in the whole network, software testing measurement, how to optimize software testing cost and improve efficiency --- hot
Maui initial experience: Cool
Use DFS to solve the problem of "number of dictionary rows"
全网讲的最细,软件测试度量,怎样优化软件测试成本提高效率---火爆
Golden nine silver ten interview season, you are welcome to take away the interview questions (with detailed answer analysis)
Laravel new route file
Service avalanche effect
C read / write binary file
C# 读写二进制文件
The backtracking of stack is used to solve the problem of "the longest absolute path of file"
Blazor University (11) component - replace attributes of subcomponents
A set of C interview questions about memory alignment. Many people make mistakes!
先中二叉建树
.NET7之MiniAPI(特别篇):.NET7 Preview3
Using positive and negative traversal to solve the problem of "the shortest distance of characters"
Using stack to solve the problem of "mini parser"