当前位置:网站首页>[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
边栏推荐
- 使用栈来解决”迷你语法分析器“的问题
- c#语法糖模式匹配【switch 表达式】
- 交换二叉树中每个结点的左和右
- 2022山东省安全员C证上岗证题库及在线模拟考试
- ASP.NET和ASP.NETCore多环境配置对比
- ASP. Net 6 middleware series - conditional Middleware
- 中后二叉建树
- Realize QQ login with PHP
- Mise en service PID du moteur de codage (anneau de vitesse | anneau de position | suivant)
- Blazor University (11) component - replace attributes of subcomponents
猜你喜欢
Source Generator实战
Notes sur le développement de la tarte aux framboises (XII): commencer à étudier la suite UNO - 220 de la tarte aux framboises de contrôle industriel advantech (i): Introduction et fonctionnement du s
ASP. Net 6 middleware series - conditional Middleware
C语言实现通讯录----(静态版本)
Ningde's position in the times is not guaranteed?
Yes Redis using distributed cache in NE6 webapi
最通俗易懂的依赖注入与控制反转
Xamarin effect Chapter 22 recording effect
Laravel's own paging query
Development notes of raspberry pie (12): start Advantech industrial control raspberry pie uno-220 Kit (I): introduction and operation of the system
随机推荐
队列的存储和循环队列
c#语法糖模式匹配【switch 表达式】
使用两种方法来解决“最大回文数乘积”问题
Source code interpretation of Flink index parameters (read quantity, sent quantity, sent bytes, received bytes, etc.)
The backtracking of stack is used to solve the problem of "the longest absolute path of file"
Thoughts on the 2022 national network security competition of the national secondary vocational group (only one idea for myself) - network security competition questions (10)
搭建XAMPP时mysql端口被占用
TP5 where query one field is not equal to multiple values
Thoughts on the 2022 national network security competition of the national secondary vocational group (only one idea for myself) - network security competition questions (8)
MAUI初体验:爽
[ncnn] - the meaning of - 23300 in param
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
Laravel new route file
腾讯视频涨价:一年多赚74亿!关注我领取腾讯VIP会员,周卡低至7元
MYSQL_ From mastery to abandonment
Ningde's position in the times is not guaranteed?
最通俗易懂的依赖注入与控制反转
Use of slice grammar sugar in C #
ASP. Net and ASP NETCORE multi environment configuration comparison
2022年P气瓶充装培训试题及模拟考试