背景:某个字段的数据中是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