码迷,mamicode.com
首页 > Web开发 > 详细

vertica提取json字段值

时间:2020-01-14 14:48:04      阅读:164      评论:0      收藏:0      [点我收藏+]

标签:from   nbsp   内容   ica   when   div   weight   ase   class   

json字符串的内容如下:

[{"stockName":"阳光照明","stockProfit":"5500.0000","stockCode":"600261"},{"stockName":"京 运 通","stockProfit":"6664.5000","stockCode":"601908"}]

 

通过regexp_substr和regexp_instr函数来提取stockcode字段值,返回前3个值。SQL如下:

select
  substr(regexp_substr(f1, stockCode":"(\w)+), 13) as code1,
  (case when regexp_instr(f1, stockCode":"(\w)+) > 0 then
    substr(regexp_substr(f1, stockCode":"(\w)+, regexp_instr(f1, stockCode":"(\w)+) + 1), 13) 
  else null end) as code2,
  (case when regexp_instr(f1, stockCode":"(\w)+) > 0 and regexp_instr(f1, stockCode":"(\w)+, regexp_instr(f1, stockCode":"(\w)+) + 1) > 0 then
    substr(regexp_substr(f1, stockCode":"(\w)+, regexp_instr(f1, stockCode":"(\w)+, regexp_instr(f1, stockCode":"(\w)+) + 1) + 1), 13)
  else null end) as code3
from t1

 

vertica提取json字段值

标签:from   nbsp   内容   ica   when   div   weight   ase   class   

原文地址:https://www.cnblogs.com/lavezhang/p/12191852.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!