在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

 

上一篇:vue3中如何像vue2中注册全局插件


下一篇:mac系统从dmg文件转换成iso文件