1. 示例:
JSON_EXTRACT()
是JSON
提取函数,$.name
就是一个JSON path
,表示定位文档的 name
字段.JSON path
是以 $
开头,下面看一个示例:
{ "num": 123, "arr": [1,2], "obj": { "a": 3, "b": 4 } } $.num //结果:123 $.arr //结果:[1, 2] $.arr[1] //结果:1 $.obj.a //结果:3
2. 应用实例:
select oi.oi_id order_item_id, replace(JSON_EXTRACT(o.coupon_json,'$.couponPlatDTO.c_sn'),'"','') coupon_sn from fx_orders_items oi INNER JOIN fx_orders o on oi.o_id = o.o_id where o.o_id = 6947877031523765285; ## replace(str,'"','') -- 将str中双引号"替换为空
o.coupon_json对应的数据示例:
{ "couponPlatDTO": { "c_sn": "HYQD1219100037457642053929", "couponBatchId": "cb_130011", "couponBatchName": 牌-满99减10元电商券", "couponDenominationPrice":"10", "couponPlatDiscountPrice":"10.00", "useCoupon":1 } "usePlatCoupon":1, "useStoreCoupon":0 }