数据库中对json的创建修改操作

数据库中对json的创建修改操作
创建数据库的表包含json的字段

create table tab_json(id int not null auto_increment primary key,data json);
insert into tab_json values (null,'{"name":"Mike","address":"Beijing","tel":13249872314}');

通过json_set函数,来修改data字段的值

update tab_json set data = json_set(data,"$.address","Guangzhou") where id = 1;  #对id = 1的行的address的键值进行修改.
update tab_json set data = json_set(data,"$.address","Shenzhen");
update tab_json set data = json_set(data,"$.address","Hangzhou") where id = 2; #对id为2的address键值进行修改
update tab_json set data = json_set(data,"$.passcode","654567") where id = 1;  #对id为1的passcode字段进行修改,发现没有这个键值,就增加了一个键值对.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值