Oracle extract json fields using regular expression with oracle regexp_substr

若如初见. 提交于 2019-12-25 18:23:52

问题


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

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.

I'm using this query:

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


回答1:


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;


来源:https://stackoverflow.com/questions/36479090/oracle-extract-json-fields-using-regular-expression-with-oracle-regexp-substr

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!