SQL: search/replace but only the first time a value appears in record

后端 未结 9 814
执念已碎
执念已碎 2020-12-11 02:11

I have html content in the post_content column.

I want to search and replace A with B but only the first time A appears in the record as it may appear more than onc

9条回答
  •  一整个雨季
    2020-12-11 03:14

    To keep the sample of gjreda a bit more simple use this:

    UPDATE wp_post
        SET post_content =
                CONCAT(
                    REPLACE(LEFT(post_content, 1), 'A', 'B'),
                    SUBSTRING(post_content, 2)
                ) 
        WHERE post_content LIKE 'A%';
    

提交回复
热议问题