Mysql string interception function SUBSTRING usage instructions

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)  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 (by The intercepted field is intercepted from the first position)  substring (the intercepted field is intercepted from the first position, and the length is intercepted)  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 the length from the last number to the end of the string or intercepted)  4. Intercept string substring_index (str, delim, count)  by keyword Description: substring_index (intercepted field, keyword, number of times the keyword appears)  



 











 


Example: select substring_index("blog.jb51.net", ".", 2) as abstract from my_content_t 
Result: blog.jb51 
(Note: If the number of occurrences of the keyword is a negative number such as -2, it is counted down from the back to the character end of 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=326377976&siteId=291194637