mysql 修改JSON类型中某个字段的值

mysql  修改JSON类型中某个字段的值

mysql  修改JSON类型中某个JSON字段的值

例:修改Facebook 里面 email 的值

{
    "Facebook": {
        "identifier": "xxxxxxxxxxx",
        "profileURL": "none",
        "webSiteURL": "none",
        "photoURL": "none",
        "displayName": "test2 test2",
        "description": "none",
        "firstName": "test2",
        "lastName": "test2",
        "gender": 2,
        "language": "none",
        "age": "none",
        "birthDay": "none",
        "birthMonth": "none",
        "birthYear": "none",
        "email": "test@test.com",
        "emailVerified": "none",
        "Added": null,
        "phone": "none",
        "address": "none",
        "country": "none",
        "region": "none",
        "city": "none",
        "zip": "none"
    },
    "Google": {
        "identifier": "xxxxxxxxxxxxxxxxxxxxxx",
        "profileURL": "none",
        "webSiteURL": "none",
        "photoURL": "none",
        "displayName": "test2 test2",
        "description": "none",
        "firstName": "test2",
        "lastName": "test2",
        "gender": 2,
        "language": "none",
        "age": "none",
        "birthDay": "none",
        "birthMonth": "none",
        "birthYear": "none",
        "email": "test@test.com",
        "emailVerified": "none",
        "Added": null,
        "phone": "none",
        "address": "none",
        "country": "none",
        "region": "none",
        "city": "none",
        "zip": "none"
    }
}

sql

UPDATE 表名称 SET 字段名称= json_set(字段名称,'$.Facebook.email',“需要替换的内容”) where 条件

如果是json 里面套json  $后面跟最后一层JSON对应的名称就行,会自动去匹配的

如果修改报错,提示   Data truncation: Invalid JSON text in argument 1 to function json_set: "Invalid encoding in string." at position 161.

是因为json字段的内容不符合json格式,将其修改后重新修改即可。

SELECT id FROM ( SELECT id, CASE WHEN JSON_VALID(json) THEN JSON_EXTRACT(json, "$.dictParameters") ELSE NULL END AS result FROM monitor_work_crawl_task  WHERE  crawl_type =0 )a WHERE a.result IS NULL;
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值