当前位置:网站首页>[MySQL] left Function | Right Function
[MySQL] left Function | Right Function
2022-04-23 03:09:00 【Quand Camellia fleurit.】
1.LEFTFonctions
LEFTFonctions Utilisé à partir d'une chaîne donnée Gauche Extraire un nombre spécifié de caractères
Structure grammaticale
LEFT(str,len)
str: Chaîne donnée,Les caractères seront extraits de son côté gauche
len: Nombre de caractères à extraire,Si ce paramètre est supérieur au nombre de caractères dans la chaîne,Cette fonction renvoie la chaîne réelle
Attention!: Si l'un des paramètres estNull,Retour des résultatsNull
Exemple
-- Le résultat est vide
SELECT LEFT('abcdefg',0);
-- abc
SELECT LEFT('abcdefg',3);
-- abcdefg
SELECT LEFT('abcdefg',10);
-- Null
SELECT LEFT('abcd',NULL);
-- LEFTLa fonction peut intercepter les nombres
-- 12
SELECT LEFT(123456,2);
2.RIGHTFonctions
RIGHTFonctions Utilisé à partir d'une chaîne donnée À droite. Extraire un nombre spécifié de caractères
Structure grammaticale
RIGHT(str,len)
str: Chaîne donnée,Les caractères seront extraits de son côté droit
len: Nombre de caractères à extraire,Si ce paramètre est supérieur au nombre de caractères dans la chaîne,Cette fonction renvoie la chaîne réelle
Attention!: Si l'un des paramètres estNull,Retour des résultatsNull
Exemple
-- Le résultat est vide
SELECT RIGHT('abcdefg',0);
-- efg
SELECT RIGHT('abcdefg',3);
-- abcdefg
SELECT RIGHT('abcdefg',10);
-- Null
SELECT RIGHT('abcd',NULL);
-- RIGHTLa fonction peut intercepter les nombres
-- 56
SELECT RIGHT(123456,2);
Exemples d'exercices
Importer des données
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_infoTableau

Questions: Crypter le numéro de téléphone cellulaire de l'employé (Par exemple:138****9401) , Par ordre croissant de salaire name,phone,salaryFormat données de sortie
SELECT name, CONCAT(LEFT(phone,3),'****',RIGHT(phone,4))AS phone, salary
FROM employee_info
ORDER BY salary ASC;
Présentation des résultats:

版权声明
本文为[Quand Camellia fleurit.]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230309010538.html
边栏推荐
- Introduction and use of openfeign component
- C syntax sugar empty merge operator [?] And null merge assignment operator [? =]
- PID debugging of coding motor (speed loop | position loop | follow)
- Swap the left and right of each node in a binary tree
- . net core current limiting control - aspnetcoreratelimit
- Laravel's own paging query
- 【新版发布】ComponentOne 新增 .NET 6 和 Blazor 平台控件支持
- .Net Core 限流控制-AspNetCoreRateLimit
- C#中元组对象Tuple的使用
- Source Generator实战
猜你喜欢

Openfeign timeout setting

.NET点滴:说说Middleware构造中获取不到Scoped服务的问题

Yes Redis using distributed cache in NE6 webapi

Tencent video price rise: earn more than 7.4 billion a year! Pay attention to me to receive Tencent VIP members, and the weekly card is as low as 7 yuan

Distributed system services

数据挖掘系列(3)_Excel的数据挖掘插件_估计分析

Aspnetcore configuration multi environment log4net configuration file

Use of slice grammar sugar in C #

Thoughts on the 2022 national network security competition of the national secondary vocational group (only one idea for myself) - network security competition questions (7)

編碼電機PID調試(速度環|比特置環|跟隨)
随机推荐
准备一个月去参加ACM,是一种什么体验?
微软是如何解决 PC 端程序多开问题的——内部实现
Drawing polygons with < polygon / > circular array in SVG tag
Using positive and negative traversal to solve the problem of "the shortest distance of characters"
Two methods are used to solve the "maximum palindrome product" problem
Vs code setting line feed
Distributed system services
What kind of experience is it to prepare for a month to participate in ACM?
.NET7之MiniAPI(特别篇):.NET7 Preview3
手机连接电脑后,QT的QDIR怎么读取手机文件路径
C# 11 对 ref 和 struct 的改进
Opencv combines multiple pictures into video
The most understandable life cycle of dependency injection
Xamarin effect Chapter 22 recording effect
2022年P气瓶充装培训试题及模拟考试
C#语法糖空合并运算符【??】和空合并赋值运算符【 ??=】
Establishing and traversing binary tree
交换二叉树中每个结点的左和右
利用栈的回溯来解决“文件的最长绝对路径”问题
Maui initial experience: Cool