Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove tabs at start and end of varchar field in MySQL?

Tags:

mysql

I've got a field in a mysql db that's a varchar(255). I've looked at trim() to remove leading and trailing whitespace, but it seems to only handle spaces, not tab characters:

 UPDATE mytable SET textfield = TRIM(textfield);

Does anyone know how to also strip tabs off the start and end of a field?

like image 325
Ray Avatar asked Dec 20 '12 19:12

Ray


People also ask

How do I remove leading and trailing spaces in MySQL?

The TRIM() function removes leading and trailing spaces from a string.

How do I remove all spaces from a string in MySQL?

The TRIM() function returns a string that has unwanted characters removed. Note that to remove the leading spaces from a string, you use the LTRIM() function. And to remove trailing spaces from a string, you use the RTRIM() function.


1 Answers

You can still use the TRIM function, and specify the character to be trimmed:

UPDATE mytable SET email = TRIM(CHAR(9) FROM TRIM(email));
like image 111
Michael Fredrickson Avatar answered Sep 28 '22 01:09

Michael Fredrickson