首页 > 解决方案 > Mysql查询根据条件替换字段

问题描述

假设我的数据库中有这个

+-----------+---------------------------------------------------------------+
| id        | notes                                                         |
+-----------+---------------------------------------------------------------+
| 1         | {jsonmodel_type":"note", "content":[";;; A2 ;; Yer ;;;;;;;"]} |
| 2         | {jsonmodel_type":"note", "content":[";;; A3 ;; Hey ;;;;;;;"]} |            
+-----------+---------------------------------------------------------------+

我将如何编写 sql 查询来删除包含两个以上分号的注释列的任何部分。例如,我希望我的数据库之后看起来像这样。

+-----------+---------------------------------------------------------------+
| id        | notes                                                         |
+-----------+---------------------------------------------------------------+
| 1         | {jsonmodel_type":"note", "content":["A2 ;; Yer "]}            |
| 2         | {jsonmodel_type":"note", "content":["A3 ;; Hey "]}            |     
+-----------+---------------------------------------------------------------+

标签: mysqlsql

解决方案


hii也许像update t set notes = regexp_replace(notes, ';{3,}', '')


推荐阅读