mysql:如何删除字段开头或结尾的字符
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10964173/
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
mysql: How can I remove character at start or end of field
提问by user191688
I have field that contains a comma-separated list. Some old records have a comma at the beginning or end of the field. I need to remove these extra commas.
我有包含逗号分隔列表的字段。一些旧记录在字段的开头或结尾处有一个逗号。我需要删除这些额外的逗号。
Example:
例子:
,the,their,then
to the,their,then
,the,their,then
到 the,their,then
or
或者
the,their,then,
to the,their,then
the,their,then,
到 the,their,then
EDIT: I am looking for an UPDATE statement. I need to change the records.
编辑:我正在寻找 UPDATE 语句。我需要更改记录。
回答by codingbiz
回答by Vijay
@codingbiz, Thank you for the website link:
@codingbiz,感谢您提供网站链接:
Quick examples:
快速示例:
SELECT TRIM(BOTH ',' FROM fieldname) from tablename
SELECT TRIM(LEADING ',' FROM fieldname) from tablename
SELECT TRIM(TRAILING ',' FROM fieldname) from tablename
Thanks!
谢谢!
回答by Tegan Snyder
The question was how to remove the leading and trailing characters I will show you an example with an update query.
问题是如何删除前导和尾随字符,我将向您展示一个带有更新查询的示例。
UPDATE your_table_name
SET your_record_name = TRIM(BOTH ',' FROM your_record_name)
回答by RandomSeed
You are looking for the TRIM
function.
您正在寻找TRIM
功能。