Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL add space in column string

Tags:

mysql

I have an sql table named Customers. In Customers I have the column Name.

I want to add in the column Name an space after 5 characters.

Example:

From the column "Name" with the content "name1234" i want add a space at the position 4 so that the result is "name 1234".

I have try it so but it dont work.

SELECT INSERT('Name',4,0, ' ')

FROM
  Customers 

How would you do it, please help.

like image 866
saamii Avatar asked Sep 04 '25 03:09

saamii


1 Answers

What you want is to update your column values with a concatenation of the first part of the name followed by the space ' ', followed by the rest of the name.

UPDATE Customers
 SET name = CONCAT(SUBSTRING(name, 1, 5), 
     ' ', 
     SUBSTRING(name, 6));
like image 169
g_tec Avatar answered Sep 07 '25 13:09

g_tec