当前位置:网站首页>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 !
边栏推荐
- BasicVSR++: Improving Video Super-Resolutionwith Enhanced Propagation and Alignment
- 电子协会 C语言 1级 35 、银行利息
- The cloud native programming challenge ended, and Alibaba cloud launched the first white paper on application liveliness technology in the field of cloud native
- Four sets of APIs for queues
- Life planning (flag)
- com. alibaba. nacos. api. exception. NacosException
- Selenium driver ie common problem solving message: currently focused window has been closed
- [Mori city] random talk on GIS data (I)
- 2022-021ARTS:下半年开始
- tornado项目之路由装饰器
猜你喜欢

【Kubernetes系列】Kubernetes 上安装 KubeSphere

Crawler (III) crawling house prices in Tianjin

Vulhub vulnerability recurrence 76_ XXL-JOB

Knowledge payment applet dream vending machine V2
![[Flink] temporal semantics and watermark](/img/4d/cf9c7e80ea416155cee62cdec8a5bb.jpg)
[Flink] temporal semantics and watermark

BasicVSR++: Improving Video Super-Resolutionwith Enhanced Propagation and Alignment
![[web security] nodejs prototype chain pollution analysis](/img/b6/8eddc9cbe343f2439da92bf342b0dc.jpg)
[web security] nodejs prototype chain pollution analysis

电脑通过Putty远程连接树莓派

Flink memory model, network buffer, memory tuning, troubleshooting

Boosting the Performance of Video Compression Artifact Reduction with Reference Frame Proposals and
随机推荐
System architecture design of circle of friends
Deep profile data leakage prevention scheme
Summary of MySQL common judgment functions!! Have you used it
[freertos] freertos Learning notes (7) - written freertos bidirectionnel Link LIST / source analysis
博客停更声明
How to input single quotation marks and double quotation marks in latex?
2022 - 021arts: début du deuxième semestre
Handwritten easy version flexible JS and source code analysis
Write a thread pool by hand, and take you to learn the implementation principle of ThreadPoolExecutor thread pool
window上用.bat文件启动项目
The crackdown on Huawei prompted made in China to join forces to fight back, and another enterprise announced to invest 100 billion in R & D
Research on an endogenous data security interaction protocol oriented to dual platform and dual chain architecture
2022-021rts: from the second half of the year
Redis - detailed explanation of cache avalanche, cache penetration and cache breakdown
提升复杂场景三维重建精度 | 基于PaddleSeg分割无人机遥感影像
[network data transmission] FPGA based development of 100M / Gigabit UDP packet sending and receiving system, PC to FPGA
Master-slave replication principle of MySQL database
Guoguo took you to write a linked list, and the primary school students said it was good after reading it
notepad++如何统计单词数量
[web security] nodejs prototype chain pollution analysis