Mysql json

 最基础的保存和取数,适合科普给没用过json的:

#如果t_asset_bussiness_json表不存在type=1,property_order_id=1的数据:
insert into t_asset_bussiness_json (type, property_order_id, order_id, bussiness_json)
values (1,1,null,'{"actualfee":153.05,"expextfee":200.00}');

#如果表中存在type=1,property_order_id=1 的数据
update t_asset_bussiness_json
set bussiness_json= ifnull(
    json_set(bussiness_json,'$.actualfee',153.05,'$.expextfee',200.00), #bussiness_json中已有数据
    json_object('actualfee',153.05,'expextfee',200.00)) #bussiness_json字段为null
where type=1 and property_order_id = 1;

#取数据
select json_unquote(json_extract(bussiness_json,'$.actualfee')) from t_asset_bussiness_json;

#更新数据,将actualfee更新为5000
update t_asset_bussiness_json
set bussiness_json= json_set(bussiness_json,'$.actualfee',5000.00)
where type=1 and property_order_id = 1;
p1|p2|p3 匹配 p1 或 p2 或 p3。例如,'z|food' 能匹配 "z" 或 "food"。'(z|f)ood' 则匹配 "zood" 或 "food"。

使用正则表达式在json数组中匹配多个值:

设置变量: 

查询:

select * from tb_workbussinessjsoninfo where
(BussinessJson->'$[*]') regexp '0101|0105';
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值