问题
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