当前位置:网站首页>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 !
边栏推荐
- [thread pool]
- Improve the accuracy of 3D reconstruction of complex scenes | segmentation of UAV Remote Sensing Images Based on paddleseg
- Recursive Fusion and Deformable Spatiotemporal Attention for Video Compression Artifact Reduction
- 2022-021ARTS:下半年開始
- 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)
- 2022-021ARTS:下半年开始
- Status of the thread
- tornado之目录
- [FPGA tutorial case 7] design and implementation of counter based on Verilog
- There is no Chinese prompt below when inputting text in win10 Microsoft Pinyin input method
猜你喜欢
Amd RX 7000 Series graphics card product line exposure: two generations of core and process mix and match
Unity opens the explorer from the inspector interface, selects and records the file path
Campus network problems
The number of patent applications in China has again surpassed that of the United States and Japan, ranking first in the world for 11 consecutive years
window上用.bat文件启动项目
[Valentine's day] - you can change your love and write down your lover's name
Solution of running crash caused by node error
Splicing plain text into JSON strings - easy language method
socket inet_ pton() inet_ Ntop() function (a new network address translation function, which converts the expression format and numerical format to each other. The old ones are inet_aton(), INET_ ntoa
The cloud native programming challenge ended, and Alibaba cloud launched the first white paper on application liveliness technology in the field of cloud native
随机推荐
电脑通过Putty远程连接树莓派
手写简易版flexible.js以及源码分析
window上用.bat文件启动项目
leetcode825. Age appropriate friends
The most effective futures trend strategy: futures reverse merchandising
Unity opens the explorer from the inspector interface, selects and records the file path
Go learning notes - constants
Literature collation and thesis reading methods
Rhcsa the next day
Types of references in BibTex
Computer connects raspberry pie remotely through putty
[Chongqing Guangdong education] National Open University spring 2019 770 real estate appraisal reference questions
Selenium driver ie common problem solving message: currently focused window has been closed
Routing decorator of tornado project
jdbc连接es查询的时候,有遇到下面这种情况的大神嘛?
Detailed introduction to the big changes of Xcode 14
[FreeRTOS] FreeRTOS learning notes (7) - handwritten FreeRTOS two-way linked list / source code analysis
Cell reports: Wei Fuwen group of the Institute of zoology, Chinese Academy of Sciences analyzes the function of seasonal changes in the intestinal flora of giant pandas
Solution of running crash caused by node error
NLP literature reading summary