sql用concat语句在post_content字段前/后追加内容
最近需要在WordPress博客文章内容后面增加统一的内容,这个需要更改数据库wp_posts表里面的post_content字段,统一对post_content字段进行内容追加,具体sql语句如下:
update wp_posts set post_content = concat(post_content,"追加的内容") where 条件;
这里需要用到set和concat语法,后面的条件根据具体需求来进行设置,如果可以指定id等于多少的时候,也可以指定分类具体是修改哪个分类下面的文章,比如下面代码就是修改分类id=5时的分类文章。
update wp_posts set post_content = concat(post_content,"追加的内容") where id in (SELECT a.id FROM (select ID from wp_posts,wp_term_relationships,wp_term_taxonomy where ID=object_id and wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id and post_type='post' and post_status = 'publish' and wp_term_relationships.term_taxonomy_id = 5 and taxonomy = 'category') as a)
concat语法其他用法举例:
例子1:
SELECT CONCAT (Region_Name, Store_Name) FROM Geography WHERE Store_Name = 'Boston';
EastBoston
例子2:
mysql向表中某字段后面追添加字符串:
update table_name set field=CONCAT(field, str);
mysql向表中某字段前面添加字符串:
update table_name set field=CONCAT(str, field);
评论