前提
表名 :tableName
json字段名: json_data
json字段值: {“name”:“喵”,“age”:12}
1、可以直接通过update 的set进行修改
update tableName set json_data = '{"name":"喵","age":12}' where id = 123456;
json文件本里面没有转义字符的时候可以使用这个
2、用json_set来设置
2.1、修改本json里面已经有的字段的值
update tableName set json_data = json_set(json_data, '$.name', '刘溜溜') where id = 123456789;
2.2、同时修改两个json里面存在的字段的值
update tableName set json_data = json_set(josn_data, '$.name', '喵喵喵', '$.age', 120) where id = 123456789;
2.3、新增一个本来没有的字段和值
update tableName set json_data = json_set(josn_data, '$.address', '北京') where id = 123456789;