当前位置:网站首页>[Mysql] LEFT函數 | RIGHT函數
[Mysql] LEFT函數 | RIGHT函數
2022-04-23 03:09:00 【山茶花開時。】
1.LEFT函數
LEFT函數用於從給定字符串的左側提取指定數量的字符
語法結構
LEFT(str,len)
str: 給定的字符串,將從其左側提取字符
len: 要提取的字符數,如果此參數大於字符串中的字符數,則此函數將返回實際的字符串
注意: 如果任一參數為Null,結果返回Null
示例
-- 結果為空
SELECT LEFT('abcdefg',0);
-- abc
SELECT LEFT('abcdefg',3);
-- abcdefg
SELECT LEFT('abcdefg',10);
-- Null
SELECT LEFT('abcd',NULL);
-- LEFT函數可以截取數字
-- 12
SELECT LEFT(123456,2);
2.RIGHT函數
RIGHT函數用於從給定字符串的右側提取指定數量的字符
語法結構
RIGHT(str,len)
str: 給定的字符串,將從其右側提取字符
len: 要提取的字符數,如果此參數大於字符串中的字符數,則此函數將返回實際的字符串
注意: 如果任一參數為Null,結果返回Null
示例
-- 結果為空
SELECT RIGHT('abcdefg',0);
-- efg
SELECT RIGHT('abcdefg',3);
-- abcdefg
SELECT RIGHT('abcdefg',10);
-- Null
SELECT RIGHT('abcd',NULL);
-- RIGHT函數可以截取數字
-- 56
SELECT RIGHT(123456,2);
練習案例
導入數據
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錶
問題: 將員工手機號碼進行加密處理(例如:138****9401) ,按薪資昇序進行name,phone,salary格式輸出數據
SELECT name, CONCAT(LEFT(phone,3),'****',RIGHT(phone,4))AS phone, salary
FROM employee_info
ORDER BY salary ASC;
結果展示:
版权声明
本文为[山茶花開時。]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230309010538.html
边栏推荐
- . net tip: talk about the problem that the scoped service cannot be obtained in the middleware structure
- 全网讲的最细,软件测试度量,怎样优化软件测试成本提高效率---火爆
- 搭建XAMPP时mysql端口被占用
- Using stack to solve the problem of "mini parser"
- Simple example of using redis in PHP
- 一套关于 内存对齐 的C#面试题,做错的人很多!
- C# 11 的这个新特性,我愿称之最强!
- [format] simple output (2)
- What kind of experience is it to prepare for a month to participate in ACM?
- ASP. Net and ASP NETCORE multi environment configuration comparison
猜你喜欢
Response processing of openfeign
2022G2电站锅炉司炉考试题库及在线模拟考试
ASP.NET 6 中间件系列 - 自定义中间件类
Impact of AOT and single file release on program performance
ASP. Net 6 middleware series - conditional Middleware
The backtracking of stack is used to solve the problem of "the longest absolute path of file"
ASP.NET 6 中间件系列 - 条件中间件
C# 11 的这个新特性,我愿称之最强!
How does Microsoft solve the problem of multiple programs on PC side -- internal implementation
LNMP MySQL allows remote access
随机推荐
Establishing and traversing binary tree
基于.NetCore开发博客项目 StarBlog - (1) 为什么需要自己写一个博客?
Xamarin效果第二十二篇之录音效果
Creating wechat voucher process with PHP
建立与遍历二叉树
C introduction of variable parameter params
Source code interpretation of Flink index parameters (read quantity, sent quantity, sent bytes, received bytes, etc.)
Tencent video VIP member, weekly card special price of 9 yuan! Tencent official direct charging, members take effect immediately!
腾讯视频涨价:一年多赚74亿!关注我领取腾讯VIP会员,周卡低至7元
Recommend reading | share the trader's book list and ask famous experts for trading advice. The trading is wonderful
腾讯视频VIP会员,周卡特价9元!腾讯官方直充,会员立即生效!
Response processing of openfeign
Judge whether there is a leap year in the given year
Swap the left and right of each node in a binary tree
ASP.NET 6 中间件系列 - 自定义中间件类
Use DFS to solve the problem of "number of dictionary rows"
7-11 重排链表 (25 分)
yes. Net future
Find the number of leaf nodes of binary tree
由于3²+4²=5²,所以称‘3,4,5‘为勾股数,求n(包括n)以内所有勾股数数组。