当前位置:网站首页>[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
边栏推荐
猜你喜欢
2022山东省安全员C证上岗证题库及在线模拟考试
Blazor University (12)组件 — 组件生命周期
The most easy to understand service container and scope of dependency injection
荐读 | 分享交易员的书单,向名家请教交易之道,交易精彩无比
再战leetcode (290.单词规律)
Service avalanche effect
xutils3修改了我提报的一个bug,开心
2022A特种设备相关管理(电梯)上岗证题库及模拟考试
Development notes of raspberry pie (12): start Advantech industrial control raspberry pie uno-220 Kit (I): introduction and operation of the system
be based on. NETCORE development blog project starblog - (1) why do you need to write your own blog?
随机推荐
最通俗易懂的依赖注入之服务容器与作用域
Xamarin效果第二十二篇之录音效果
. net core current limiting control - aspnetcoreratelimit
C# WPF UI框架MahApps切换主题
Ningde's position in the times is not guaranteed?
使用split来解决“最常见的单词”问题
[new version release] componentone added Net 6 and blazor platform control support
The most easy to understand service container and scope of dependency injection
Judge whether there is a leap year in the given year
be based on. NETCORE development blog project starblog - (1) why do you need to write your own blog?
ASP.NET和ASP.NETCore多环境配置对比
Opencv combines multiple pictures into video
Openfeign details show
c#可变参数params的介绍
Use split to solve the "most common words" problem
Find the number of leaf nodes of binary tree
搭建XAMPP时mysql端口被占用
C language to achieve address book - (static version)
Blazor University (11) component - replace attributes of subcomponents
Development notes of raspberry pie (12): start Advantech industrial control raspberry pie uno-220 Kit (I): introduction and operation of the system