我正在使用带有正则表达式的Oracle查询和oracle regexp_substr 来从 JSON 字符串中提取json字段。
当我尝试获取代码键的值时,它运行良好及其值,但是当我尝试获取结果键的值时,它返回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;
此查询有什么问题? 感谢
答案 0 :(得分:1)
允许不同的数据格式。这导致{"name":"osama"}
我希望是你想要的:
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;