当前位置:首页 > Web开发 > 正文

13 ) else null end ) as code2

2024-03-31 Web开发

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字段值

温馨提示: 本文由Jm博客推荐,转载请保留链接: https://www.jmwww.net/file/web/31570.html