最基础的保存和取数,适合科普给没用过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';