MySQL 删除MYSQL中的部分字符串
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6681910/
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
Deleting part of a string in MYSQL
提问by Mike Jones
I want to delete part of a string found in a particular field.
我想删除在特定字段中找到的部分字符串。
For example, the entry in the field could be "01365320APS". The "APS" is what I am looking at deleting.
例如,字段中的条目可能是“01365320 APS”。“APS”是我要删除的内容。
My question is, should I use:
我的问题是,我应该使用:
SELECT SUBSTRING_INDEX('fieldname','APS', 1)
回答by Jacob
When you want to edit a field, you need an UPDATE
statement:
当你想编辑一个字段时,你需要一个 UPDATE
语句:
UPDATE table SET fieldname=REPLACE(fieldname,'APS','')
REPLACE
is a string function that replaces every occurence of the 2nd string in the 1st string with the 3rd one.
REPLACE
是一个字符串函数,它用第三个字符串替换第一个字符串中第二个字符串的每个出现。
Please try this with a WHERE
clause first, to see if it is really what you want to do.
请先用WHERE
子句试试这个,看看它是否真的是你想要做的。
回答by AJ.
For everyoccurrence of APS, try this:
对于每次出现的 APS,请尝试以下操作:
UPDATE table SET column=REPLACE(column,'APS','');
Reference: http://dev.mysql.com/doc/refman/5.5/en/string-functions.html#function_replace
参考:http: //dev.mysql.com/doc/refman/5.5/en/string-functions.html#function_replace