分割字符串 mysql
时间: 2023-08-25 14:18:42 浏览: 103
回答: 在MySQL中,可以使用SUBSTRING_INDEX函数来分割字符串。该函数的语法为SUBSTRING_INDEX(str, delim, count),其中str是需要拆分的字符串,delim是分隔符,count表示要取的分隔符的位置。如果count是正数,那么它将返回第n个分隔符之前的所有字符;如果count是负数,那么它将返回倒数第n个分隔符之后的所有字符。 根据给定的例子,如果我们要分割字符串'7654,7698,7782,7788',并取第一个逗号之前的所有字符,我们可以使用以下MySQL查询语句:SELECT SUBSTRING_INDEX(SUBSTRING_INDEX('7654,7698,7782,7788', ',', 1), ',', -1) AS num FROM mysql.help_topic WHERE help_topic_id < LENGTH('7654,7698,7782,7788') - LENGTH(REPLACE('7654,7698,7782,7788', ',', '')) + 1; [1 这将返回结果7654。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *2* [MySQL——字符串拆分(含分隔符的字符串截取)](https://blog.csdn.net/JoeBlackzqq/article/details/89880424)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
- *3* [mysql字符切割的四种方式](https://blog.csdn.net/qq_37260640/article/details/79731295)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文