当前位置:网站首页>[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
边栏推荐
- 手机连接电脑后,QT的QDIR怎么读取手机文件路径
- 使用DFS来解决“字典序排数”问题
- 最通俗易懂的依赖注入之生命周期
- 荐读 | 分享交易员的书单,向名家请教交易之道,交易精彩无比
- 最通俗易懂的依赖注入之服务容器与作用域
- Fight leetcode again (290. Word law)
- First in the binary tree
- Golden nine silver ten interview season, you are welcome to take away the interview questions (with detailed answer analysis)
- Maui initial experience: Cool
- Service avalanche effect
猜你喜欢

Development notes of raspberry pie (12): start Advantech industrial control raspberry pie uno-220 Kit (I): introduction and operation of the system

Blazor University (11) component - replace attributes of subcomponents

2022T电梯修理考试模拟100题及在线模拟考试

全网讲的最细,软件测试度量,怎样优化软件测试成本提高效率---火爆

Xamarin效果第二十二篇之录音效果

搭建XAMPP时mysql端口被占用

Detailed log display of openfeign call

How does Microsoft solve the problem of multiple PC programs

C语言实现通讯录----(静态版本)

. net tip: talk about the problem that the scoped service cannot be obtained in the middleware structure
随机推荐
利用栈的回溯来解决“文件的最长绝对路径”问题
. net tip: talk about the problem that the scoped service cannot be obtained in the middleware structure
ASP. Net 6 middleware series - execution sequence
Two methods are used to solve the "maximum palindrome product" problem
Thoughts on the 2022 national network security competition of the national secondary vocational group (only one idea for myself) - network security competition questions (7)
对.NET未来的一点感悟
Thoughts on the 2022 national network security competition of the national secondary vocational group (only one idea for myself) - network security competition questions (10)
The most easy to understand service container and scope of dependency injection
[format] simple output (2)
Use of metagroup object tuple in C
2022T电梯修理考试模拟100题及在线模拟考试
Passing object type parameters through openfeign
TP5 email (2020-05-27)
Source Generator实战
基于.NetCore开发博客项目 StarBlog - (2) 环境准备和创建项目
Establishing and traversing binary tree
C# WPF UI框架MahApps切换主题
Small companies don't make formal offers
C# 11 的这个新特性,我愿称之最强!
全网最全,接口自动化测试怎么做的?精通接口自动化测试详解