Oracle使用带有regreg_substr的正则表达式提取json字段 [英] Oracle extract json fields using regular expression with oracle regexp_substr

查看:1137
本文介绍了Oracle使用带有regreg_substr的正则表达式提取json字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用带有正则表达式的Oracle查询和oracle regexp_substr JSON 字符串中提取json字段.

I'm using Oracle query with regular expression and oracle regexp_substr to extract json fields from JSON string.

当我尝试获取代码键的值时,它可以正常工作并获得其值,但是当我尝试获取结果键的值时,它返回null.

whene I try to get the value of code key it working well and its value, but whene i try to get the value of results key it return null.

我正在使用此查询:

select regexp_replace(regexp_substr('{"code":"001","message":"success","transactionId":437,"results":{"name":"osama"}}','"results":\s*("(\w| )*")', 1, level), '"results":\s*"((\w| )*)"', '\1', 1, 1) results
 from dual
connect by regexp_substr('{"code":"001","message":"success","transactionId":437,"results":{"name":"osama"}}', '"results":\s*("(\w| )*")', 1, level) is not null;

此查询出了什么问题? 谢谢

What is wrong in this query? Thanks

推荐答案

允许使用不同的数据格式.结果是{"name":"osama"},我希望这是您想要的:

Allowing for the different data format. This results in {"name":"osama"} which I hope is what you want:

select regexp_replace(regexp_substr('{"code":"001","message":"success","transactionId":437,"results":{"name":"osama"}}','"results":\s*{"(.*| )*"\}', 1, level), '"results":\s*(\{.*\})', '\1', 1, 1) results
 from dual
connect by regexp_substr('{"code":"001","message":"success","transactionId":437,"results":{"name":"osama"}}', '"results":\{(.*)"\}', 1, level) is not null;

这篇关于Oracle使用带有regreg_substr的正则表达式提取json字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆