May 15, 2021 MySQL
select left(content,200) as abstract from my_content_t
2, intercept the string from the right
select right(content,200) as abstract from my_content_t
3, intercept the string
Cases:
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 countdown to the end of the string or the length of the interception)
4, by keyword to intercept the string
substring_index(str,delim,count)
Description: substring_index (intercepted fields, separators, number of keyword appearances)
Cases:
select substring_index("www.w3cschool.cn",".",2) as abstract from wiki_user
Results:
www.w3cschool
(Note: If the number of times the keyword appears is negative, such as -2, it is the last countdown to the end of the string)
Introduction to functions:
SUBSTRING(str,pos) , SUBSTRING(str FROM pos) SUBSTRING(str,pos,len) , SUBSTRING(str FROM pos FOR len)
Formats without len parameters return a substring from the string str, starting at the position pos. T he format with the len parameter returns a substring the same length as the len character from the string str, starting at the position pos. U se the FROM format as the standard SQL syntax. Y ou may also use a negative value for pos. I f so, the position of the substring starts with the pos character at the end of the string, not at the beginning of the string. You can use a negative value for pos in functions in the following format.