当前位置:网站首页>Text processing function sorting in mysql, quick search of collection
Text processing function sorting in mysql, quick search of collection
2022-07-04 07:26:00 【Python and data analysis】
Hello everyone , I'm Xiangyu !
Preface
I've arranged for a while today MySQL Text processing function in , Of course, if Xiangyu arranges and misses the message on the backstage . No matter in which programming language , The processing of text is extremely important , Because everyone knows , In daily data , Texts will account for a large part , therefore , The bosses directly encapsulate the commonly used processing operations , In this way, you don't need to write your own functions when processing text , And in fact, it also gives a friendly feeling to many new friends , For example, many data analysts
Study SQL Just want to take a number , It's not a view to learn at all 、 stored procedure 、 function , So at this point , If you can use encapsulated built-in functions directly , That's the gospel of my friends , Said so much , That is to say, text processing functions are very important , Of course , Xiangyu has tidied up here , You can collect , When you need it, just check it quickly , Don't bother, you can also try to tidy up like Xiangyu .
1. Mind mapping
2. Using examples
The following example does not specifically look up the table , Direct use select To test .
2.1 Interception and splicing
left: Left hand intercept , From the front ( On the left ) Intercept a certain length of substring for the string backwards , grammar :left( character string , Interception length )
select left(' The Yangtze River flows east ',4); -- return “ Rolling Yangtze River ”
right: Right intercept , From the back ( On the right ) Truncate a certain length of substring to the string forward , grammar :right( character string , Interception length )
select right(' The Yangtze River flows east ',4); -- return “ The east of the river is flowing ”
substring : Intercept the substring with specified position and length for the string , grammar :substring( character string , From the first few characters [, Interception length ])
Be careful : The grammatical [] Indicates that this parameter can be defaulted
The third parameter of this function can be defaulted ( No ), By default, it means to intercept the last character
select substring(' Rolling Yangtze River board ',3); -- return “ Changjiang board of directors ”
select substring(' The rolling Yangtze River is full of water ',3,2); -- return “ Yangtze River ”
concat: String splicing , grammar :concat( character string 1[, character string 2, character string 3,…])
The parameters of this function can be given to one or more , When the parameter has null when , The result also returns null
select concat(' Rolling ') -- return “ Rolling ”
select concat(' Rolling ',null) -- return null
select concat(' Rolling ',' Yangtze River ',' East death ',' water ') -- return “ The Yangtze River flows east ”
2.2 transformation
lower: Convert to lowercase , grammar :lower( String to be converted )
select lower('HELLO,WORLD'); -- return “hello,world”
upper : Convert to uppercase , grammar :upper( String to be converted )
select upper('hello,world'); -- return "HELLO,WORLD"
2.3 length
length : Returns the length of the string , grammar :length( character string )
select length(' The Yangtze River flows east '); -- return 21( One Chinese character takes up the length of three English characters )
select length('hello'); -- return 5
select length(null) -- return null
2.4 Find the substring position
locate: When a substring can be found in the original string, its first position in the original string is returned , grammar Locate( Substring , Parent string )
explain : The substring does not exist and returns 0, The substring is null return null
select locate('sql',' Xiangyu is learning mysql Or what kind sql'); -- return 8, first s Is the eighth character
select locate('pgsql',' Xiangyu is learning mysql Or what kind sql'); -- return 0
select locate(null,' Xiangyu is learning mysql Or what kind sql'); -- return null
position : and locate Function as , The writing is different , grammar position(substr in str)
select position('sql' in ' Xiangyu is learning mysql Or what kind sql'); -- return 8
instr: The function is the same as the previous two , The writing is different , grammar :instr(str,substr)
select instr(' Xiangyu is learning mysql Or what kind sql','sql'); -- return 8
2.5 Go to space
ltrim: Remove the leading space in the string , Is to remove the blank space at the beginning , grammar :ltrim( character string )
select ltrim(' It's early morning 2 spot '); -- return “ It's early morning 2 spot ”
rtrim: Remove trailing space from string , grammar :rtrim( character string )
select rtrim(' It's two in the morning '); -- return “ It's two in the morning ”
trim: Remove leading and ending spaces in the string , But it can't remove the space in the middle , grammar :trim( character string )
select trim(' Now it is In the morning At two o 'clock '); -- return “ Now it is In the morning At two o 'clock ”
2.6 fill
lpad: Returns a fixed length string , Interception beyond a fixed length , Below the fixed length, use the specified characters Left fill , grammar :lpad( character string , Fixed length , The characters that need to be filled in )
Below the fixed length
select lpad(' One gao Nest gaogao',20,'*'); -- return "******** One gao Nest gaogao"
When the fixed length is exceeded
select lpad(' Frenchman Zhang San ',4,'^^'); -- return “ Outlaw maniac ”
rpad: Returns a fixed length string , Interception beyond a fixed length , Below the fixed length, use the specified characters Right fill , grammar :rpad( character string , Fixed length , The characters that need to be filled in )
Below the fixed length
select rpad(' One gao Nest gaogao',20,'*'); -- return " One gao Nest gaogao********"
When the fixed length is exceeded
select rpad(' Frenchman Zhang San ',4,'^^'); -- return “ Outlaw maniac ”
2.7 Replace
replace: Replace the substring in the string with a new substring and return , grammar :replace( Original string , Substring to be replaced , Substring for replacement )
select replace(' The Yangtze River flows east ',' roll ',' Don't get out '); -- return “ Don't roll, don't roll, the Yangtze River flows eastward ”
Be careful : It will be completely replaced when replacing , It is not allowed to set the substring that meets the conditions
2.8 Return to pronunciation
soundex: Returns the phonetic representation of a string soundex, It helps to compare words with different spelling but similar English pronunciation , grammar :soundex( character string )
for example :
If a file named Y.LEE Wrong input when searching for customers , Below sql There will be no return results .
SELECT CUSTOMER_NAME FROM CUSTOMER WHERE CUSTOMER_NAME = 'Y LEE'
And if you write that :
SELECT CUSTOMER_NAME FROM CUSTOMER WHERE SOUNDEX(CUSTOMER_NAME) =SOUNDEX('Y LEE')
Because they sound similar , So their SOUNDEX Values match , This will return a piece of data .
soundex Refer to :https://www.cnblogs.com/shuoli/p/8099212.html
Okay ,sql The text function of is summarized here , Welcome to pay attention to add collection , At the same time, you are also welcome to Xiangyu's official account of the same name , Xiangyu is constantly updating !
边栏推荐
- 【FreeRTOS】FreeRTOS學習筆記(7)— 手寫FreeRTOS雙向鏈錶/源碼分析
- Types of references in BibTex
- [Chongqing Guangdong education] National Open University spring 2019 770 real estate appraisal reference questions
- Pangu open source: multi support and promotion, the wave of chip industry
- Selenium driver ie common problem solving message: currently focused window has been closed
- win10微软拼音输入法输入文字时候下方不出现中文提示
- 【FreeRTOS】FreeRTOS学习笔记(7)— 手写FreeRTOS双向链表/源码分析
- 大厂技术专家:架构设计中常用的思维模型
- Boosting the Performance of Video Compression Artifact Reduction with Reference Frame Proposals and
- Since DMS is upgraded to a new version, my previous SQL is in the old version of DMS. In this case, how can I retrieve my previous SQL?
猜你喜欢
User login function: simple but difficult
Boosting the Performance of Video Compression Artifact Reduction with Reference Frame Proposals and
There is no Chinese prompt below when inputting text in win10 Microsoft Pinyin input method
[Valentine's day] - you can change your love and write down your lover's name
Introduction to sap commerce cloud B2B organization function
Su Weijie, a member of Qingyuan Association and an assistant professor at the University of Pennsylvania, won the first Siam Youth Award for data science, focusing on privacy data protection, etc
[web security] nodejs prototype chain pollution analysis
Unity 从Inspector界面打开资源管理器选择并记录文件路径
Unity opens the explorer from the inspector interface, selects and records the file path
leetcode825. Age appropriate friends
随机推荐
Since DMS is upgraded to a new version, my previous SQL is in the old version of DMS. In this case, how can I retrieve my previous SQL?
2022-021ARTS:下半年开始
MySQL 数据库 - 函数 约束 多表查询 事务
[FPGA tutorial case 8] design and implementation of frequency divider based on Verilog
Crawler (III) crawling house prices in Tianjin
the input device is not a TTY. If you are using mintty, try prefixing the command with ‘winpty‘
How to buy financial products in 2022?
The most effective futures trend strategy: futures reverse merchandising
Solution of running crash caused by node error
rapidjson读写json文件
Industrial computer anti-virus
Xcode 14之大变化详细介绍
Zabbix agent主动模式的实现
节点基础~节点操作
Set JTAG fuc invalid to normal IO port
[network data transmission] FPGA based development of 100M / Gigabit UDP packet sending and receiving system, PC to FPGA
flask-sqlalchemy 循环引用
A new understanding of how to encrypt industrial computers: host reinforcement application
How can the old version of commonly used SQL be migrated to the new version?
The IP bound to the socket is inaddr_ The meaning of any htonl (inaddr_any) (0.0.0.0 all addresses, uncertain addresses, arbitrary addresses)