MySQL removes all spaces from the entire column

Is there a way to remove all spaces from a specific column for all values?

+54
mysql
Sep 06 2018-11-11T00:
source share
5 answers

to replace all spaces :

 UPDATE `table` SET `col_name` = REPLACE(`col_name`, ' ', '') 

to remove all tabs characters:

 UPDATE `table` SET `col_name` = REPLACE(`col_name`, '\t', '' ) 

to remove all new line characters:

 UPDATE `table` SET `col_name` = REPLACE(`col_name`, '\n', '') 

http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_replace

to remove the first and last space(s) column:

 UPDATE `table` SET `col_name` = TRIM(`col_name`) 

http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_trim

+117
Sep 06 2018-11-11T00:
source share

Work request:

SELECT replace(col_name , ' ','') FROM table_name;

So far this is not the case:

SELECT trim(col_name) FROM table_name;

+5
Oct. 16 '15 at 7:40
source share

Since the question is how to replace ALL spaces

 UPDATE `table` SET `col_name` = REPLACE (REPLACE(REPLACE(`col_name`, ' ', ''), '\t', ''), '\n', ''); 
+3
Jun 27 '17 at 12:39 on
source share

Using the query below, you can remove leading and trailing spaces in MySQL.

 UPDATE `table_name` SET `col_name` = TRIM(`col_name`); 
+1
Apr 13 '17 at 7:34 on
source share

Just use the following sql, you did:

 SELECT replace('Hi How are you',' ', '') output = HiHowareyou 
0
Apr 27 '17 at 6:40
source share



All Articles