在mysql5.8中用json_extract函数解析json
背景:某个字段的数据中是JSON,需要提取其中的卡号部分,如:
{"objType":"WARE","orderId":6771254073665082371,"values":["D3252","",""]}
需要提取其中的:D3252
示例如下:
select json_extract(x,'$.values[0]') 卡号
from
(
select '{"objType":"WARE","orderId":6771254073665082371,"values":["M2352","",""]}' x
union all
select '{"objType":"WARE","orderId":6771254073665082371,"values":["W3423","",""]}' x
union all
select '{"objType":"WARE","orderId":6771254073665082371,"values":["D3252","",""]}' x
) t
返回:
卡号
"M2352"
"W3423"
"D3252"
参考:https://blog.csdn.net/lkforce/article/details/102940249
本文来自博客园,作者:xiaoyongdata(微信号:xiaoyongdata),转载请注明原文链接:https://www.cnblogs.com/xiaoyongdata/p/15627481.html