简体   繁体   English

用换行的mysql替换First Space

[英]Replacing First Space with new line mysql

I am looking for a mysql query where i can replace first occurrence of Space in a string with a new line. 我正在寻找一个mysql查询,我可以用新行替换字符串中第一次出现的空格。

For example, 例如,

LSRNABC1234 This is a sample

So here I wish to insert new line after LSRNABC1234 so resulting string would look like: 因此,在这里我希望在LSRNABC1234之后插入新行, LSRNABC1234使结果字符串如下所示:

LSRNABC1234 
This is a sample

The regular find and replace queries replace everything, I am not sure how to insert new line just after first space. 常规的查找和替换查询会替换所有内容,我不确定如何在第一个空格后插入新行。

Thanks 谢谢

Try the following update: 尝试以下更新:

UPDATE yourTable
SET text = CONCAT(SUBSTRING_INDEX(text, ' ', 1),
                  CHAR(10 using utf8),     -- line break
                  SUBSTRING(text, INSTR(text, ' ') + 1));

Here is a demo showing that the string manipulation logic is working correctly: 这是一个演示字符串操作逻辑正确运行的演示:

Demo 演示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM