如何在 MySQL 中的 varchar 字段的开头和结尾删除选项卡?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13979169/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 15:52:14  来源:igfitidea点击:

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

mysql

提问by Ray

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:

我在 mysql 数据库中有一个字段,它是一个 varchar(255)。我看过 trim() 来删除前导和尾随空格,但它似乎只处理空格,而不是制表符:

 UPDATE mytable SET textfield = TRIM(textfield);

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

有谁知道如何从字段的开头和结尾剥离制表符?

回答by Michael Fredrickson

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

您仍然可以使用该TRIM函数,并指定要修剪的字符:

UPDATE mytable SET email = TRIM(CHAR(9) FROM TRIM(email));

回答by Kermit

Have you tried this?

你试过这个吗?

UPDATE mytable SET email = REPLACE(TRIM(email), CHAR(9), '')

回答by davidethell

You can use replace with either \t or CHAR(9):

您可以使用 \t 或 CHAR(9) 替换:

UPDATE mytable SET email = REPLACE(TRIM(email), '\t', '');

回答by user2715347

The TRIMfunction provides a good solution for your problem. Just use some like this above:

TRIM功能提供您的问题很好的解决方案。只需使用上面这样的一些:

UPDATE yourtable SET your_field = TRIM(CHAR(9) FROM TRIM(your_field));