用于json的oracle11g regexp_replace

时间:2017-02-16 11:55:40

标签: json oracle oracle11g

我选择了:

select regexp_replace(regexp_substr('[{"date": "01_2016", "val":"100_22"},{"date": "02_2016","val": "200.10"}]'
,'"val":\s*("(\w| )*")', 1, level)
,'"val":\s*"((\w| )*)"', '\1', 1, 1) val
from dual
connect by regexp_substr('[{"date": "01_2016", "val":"100_22"},{"date": "02_2016","val": "200.10"}]', '"val":\s*("(\w| )*")', 1, level) is not null
;

如果我的值格式为100_10,则可以。但是我想要100.10并且这个选择不支持这个。如何写regexp_replace?

2 个答案:

答案 0 :(得分:0)

使用(\d+)_(\d+)仅匹配由下划线分隔的数值:

SELECT REGEXP_REPLACE(
         '[{"date": "01_2016", "val":"100_22"},{"date": "02_2016","val": "200.10"}]',
         '"val":"(\d+)_(\d+)"',
         '"val":"\1.\2"'
       )
FROM   DUAL;

答案 1 :(得分:0)

谢谢大家。我找到了解决方案

 select regexp_replace(regexp_substr('[{"date": "01-2016", "val":"100.22"},{"date": "02-2016","val": "200.10"},{"date": "03-2016","val": "200.15"}]','"val":\s*("(\w|[..])*")', 1, level),'"val":\s*"((\w|[..])*)"', '\1', 1, 1) val, regexp_replace(regexp_substr('[{"date": "01-2016", "val":"100.22"},{"date": "02-2016","val": "200.10"},{"date": "03-2016","val": "200.15"}]' ,'"date":\s*("(\w|[-])*")', 1, level) ,'"date":\s*"((\w|[-])*)"', '\1', 1, 1) date_period from dual connect by regexp_substr('[{"date": "01-2016", "val":"100.22"},{"date": "02-2016","val": "200.10"},{"date": "03-2016","val": "200.15"}]', '"val":\s*("(\w|[..])*")', 1, level) is not null