Home  >  Article  >  Database  >  How to split a string into multiple lines in mysql

How to split a string into multiple lines in mysql

王林
王林Original
2020-09-27 16:05:587703browse

Mysql method of splitting a string into multiple lines: You can use the SUBSTRING_INDEX() function to split, such as [substring_index(substring_index(a.chain,'_',b.topic_id 1)].

How to split a string into multiple lines in mysql

You can use the string interception function SUBSTRING_INDEX to achieve this.

(Recommended tutorial: mysql video tutorial)

Syntax:

SUBSTRING_INDEX(str, delimiter, count)

Description:

Returns a substring of str, intercepted at the position where delimiter appears count times. If count > 0, count from the left, and Return the substring before the position; if count

delimiter is case-sensitive and multi-byte safe.

Example:

SELECT
    substring_index(substring_index(a.chain,'_',b.help_topic_id + 1),'_' ,- 1)AS ID
FROM
    (select '1_11_1223_1242' as chain) a  
JOIN mysql.help_topic b ON b.help_topic_id <
(length(a.chain) - length( replace(a.chain, &#39;_&#39;, &#39;&#39;)  ) + 1)

Execution result:

How to split a string into multiple lines in mysql

##Related recommendations:

php training

The above is the detailed content of How to split a string into multiple lines in mysql. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn