Home > Database > Mysql Tutorial > body text

How to split a string into multiple lines in mysql

王林
Release: 2020-09-27 16:05:58
Original
7852 people have browsed it

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)
Copy after login

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 < 0, count from the right and return the substring after the position.

delimiter is case-sensitive and multi-byte safe.

Example:

SELECT
    substring_index(substring_index(a.chain,&#39;_&#39;,b.help_topic_id + 1),&#39;_&#39; ,- 1)AS ID
FROM
    (select &#39;1_11_1223_1242&#39; 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)
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template