【问题标题】:MySQL REPLACE function not work when the text gets long当文本变长时,MySQL REPLACE 功能不起作用
【发布时间】:2020-04-05 11:16:57
【问题描述】:

我有一个表(实际上是由 WordPress 生成的)。我想使用REPLACE 函数替换一些文本,但它不起作用。

字段中的文本:

<!-- wp:blocks/amazon-product {"url":"https://www.amazon.com/OutdoorMaster-OTG-Ski-Goggles-Protection/dp/B01HLV5HR6","category":"1","headline":"OutdoorMaster OTG Ski Goggles - Over Glasses Ski/Snowboard Goggles for Men, Women \u0026 Youth - 100% UV Protection (Black Frame + VLT 10% Grey Lens with REVO Silver)","price":"$17.99","review":"",","checkPrice":"Buy Now on Amazon","isUrlPresent":true,"cacheDate":"2020-04-05T07:27:27.875Z"} /-->

这个文本完全是从字段中复制的,我尝试这样做:

UPDATE wp_posts
  SET post_content =
  REPLACE(
    post_content,
    'the above text',
    'some new text'
  )
  WHERE ID = 1;

并且没有影响行,但是当我减少文本时,假设我只为<!-- wp:blocks/amazon-product {"url":"https://www.amazon.com/OutdoorMaster-OTG-Ski-Goggles-Protection/dp/B01HLV5HR6" 做,然后文本被替换。

【问题讨论】:

    标签: mysql sql database wordpress


    【解决方案1】:

    如你所见

    Set @a = 'a<!-- wp:blocks/amazon-product {"url":"https://www.amazon.com/OutdoorMaster-OTG-Ski-Goggles-Protection/dp/B01HLV5HR6","category":"1","headline":"OutdoorMaster OTG Ski Goggles - Over Glasses Ski/Snowboard Goggles for Men, Women \u0026 Youth - 100% UV Protection (Black Frame + VLT 10% Grey Lens with REVO Silver)","price":"$17.99","review":"",","checkPrice":"Buy Now on Amazon","isUrlPresent":true,"cacheDate":"2020-04-05T07:27:27.875Z"} /-->"a'
    
    SELECT REPLACE (@a,'<!-- wp:blocks/amazon-product {"url":"https://www.amazon.com/OutdoorMaster-OTG-Ski-Goggles-Protection/dp/B01HLV5HR6","category":"1","headline":"OutdoorMaster OTG Ski Goggles - Over Glasses Ski/Snowboard Goggles for Men, Women \u0026 Youth - 100% UV Protection (Black Frame + VLT 10% Grey Lens with REVO Silver)","price":"$17.99","review":"",","checkPrice":"Buy Now on Amazon","isUrlPresent":true,"cacheDate":"2020-04-05T07:27:27.875Z"} /-->','test')
    
    |替换 (@a,'
    猜你喜欢
    • 1970-01-01
    • 2017-10-11
    • 1970-01-01
    • 2018-09-09
    • 1970-01-01
    • 2019-04-02
    • 2019-05-05
    • 2021-07-06
    • 1970-01-01
    相关资源
    最近更新 更多