使用regexp_replace字符串

时间:2016-09-03 03:41:55

标签: regex oracle regexp-replace

我正在尝试使用oracle REGEXP_REPLACE函数删除重复的字符。

字符串如下所示:

("ABC","DEF,,,,",,,"111",,,"HI")

输出应为:

("ABC","DEF,,,,","111","HI")

为实现这一目标,我尝试了以下代码

SELECT REGEXP_REPLACE(("ABC","DEF,,,,",,,"111",,,"HI")','[,]{2,}','(,))
FROM DUAL;

这是删除doble引号内的逗号。有人可以告诉我如何删除不在双引号中的重复逗号吗?

1 个答案:

答案 0 :(得分:0)

SELECT LISTAGG('"'||test||'"', ',')
     WITHIN GROUP (order by r) "t" from
(select rownum r ,regexp_substr(q'"ABC","DEF,,,,",,,"111",,,"HI"','[^"]+', 1, level) test from dual
connect by regexp_substr(q'"ABC","DEF,,,,",,,"111",,,"HI"', '[^"]+', 1, level) is not null)
where regexp_count( test, ',' ) != LENGTH(test)

这有效。