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

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

Deleting part of a string in MYSQL

mysqlsqlstring

提问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 UPDATEstatement:

当你想编辑一个字段时,你需要一个 UPDATE语句:

UPDATE table SET fieldname=REPLACE(fieldname,'APS','')

REPLACEis 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 WHEREclause 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