简体   繁体   English

使用MySQL从字段中删除字符串

[英]Remove string from field using MySQL

I want to remove the string; 我想删除字符串;

<p><span style="color: #008000;">-- Instant Download --</span></p>

from a the field description_short in the table ps_product_lang I have tried the following SQL query 从表ps_product_lang中的字段description_short中,我尝试了以下SQL查询

update ps_product_lang set description_short = replace(description_short, ‘<p><span style="color: #008000;">-- Instant Download --</span></p>’, ‘’);

But I get the error message 但是我收到错误消息

"#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '>-- Instant Download -- “#1064-您的SQL语法有误;请查看与您的MySQL服务器版本相对应的手册,以在'>-Instant Download附近使用正确的语法-

’, ‘’)' at line 1" 第1行的“,”)

I believe its the quotes and --< that may be the issue, does anyone know how to make the query work> Thanks 我相信它的引号和-<可能是问题所在,有人知道如何使查询生效>谢谢

This is your code: 这是您的代码:

update ps_product_lang
    set description_short = replace(description_short, ‘<p><span style="color: #008000;">-- Instant Download --</span></p>’, ‘’);

The only problem that is obvious to me are the curly single quotes. 对我来说,唯一明显的问题是单引号。 Try replacing them with regular single quotes: 尝试用常规单引号替换它们:

update ps_product_lang
    set description_short = replace(description_short, '<p><span style="color: #008000;">-- Instant Download --</span></p>', '');

why not to do the replace by PHP and after update the full field in mysql? 为什么不用PHP替换并更新mysql中的完整字段? Maybe is not the most correct way, but it works and is easy and fast to code that solution. 也许这不是最正确的方法,但是它可行,并且可以轻松,快速地编写该解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM