Reputation: 287
I am looking for a mysql query where i can replace first occurrence of Space in a string with a new line.
For example,
LSRNABC1234 This is a sample
So here I wish to insert new line after LSRNABC1234
so resulting string would look like:
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
Upvotes: 0
Views: 88
Reputation: 520978
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:
Upvotes: 1