mysql function substring_index()

Reprinted from https://www.cnblogs.com/lijiageng/p/6511334.html

Function: 
1. Intercept the string 
left (str, length)  from
the left Description: left (intercepted field, intercepted length) 
Example: select left (content, 200) as abstract from my_content_t 

 


2. Intercept the string 
right (str, length)  from
the right Description: right (intercepted field, intercepted length) 
Example: select right (content, 200) as abstract from my_content_t 

 


3. Intercept string 
substring (str, pos) 
substring (str, pos, length) 
description: substring (intercepted field, intercepted from the first position) 
substring (intercepted field, intercepted from the first position, intercepted length) 
Example: select substring(content,5) as abstract from my_content_t 
select substring(content,5,200) as abstract from my_content_t 
(Note: if the number of digits is negative, such as -5, it is from the last number to the end of the string or intercepted length) 

 


4. Intercept string 
substring_index (str, delim, count)  by keyword
Description: substring_index (intercepted field, keyword, number of occurrences of keyword) 
Example: select substring_index ("blog.jb51.net", ".", 2) as abstract from my_content_t 
result: blog.jb51 
(Note: If the number of times the keyword appears is negative, such as -2, it will count down from the back to the end of the string) 

 

 

Function introduction:

SUBSTRING(str,pos) , SUBSTRING(str FROM pos) SUBSTRING(str,pos,len) , SUBSTRING(str FROM pos FOR len)

The format without the len  parameter returns a substring from the string str , starting at position  pos . The format with the len parameter returns a substring of the same length as len characters from the string str , starting at position  pos . The format using FROM is standard SQL syntax. It is also possible to use a negative value for pos . If so, the position of the substring starts at the pos  character at the end of the string, not at the beginning of the string.  A negative value for pos can be used in functions of the following format .


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324931487&siteId=291194637