首页 > 解决方案 > 如何在 oracle 中使用 Regexp_Replace 替换字符串

问题描述

我想替换这个:

"STORES/KOL#10/8/36#1718.00#4165570.00#119539388#PT3624496#9902001#04266#6721#PT3624496-11608091-1-55-STORES/KOL"

有了这个:

"STORES/KOL#10#8#36#1718.00#4165570.00#119539388#PT3624496#9902001#04266#6721#PT3624496-11608091-1-55-STORES/KOL"

基本上这是基于条件的替换,我想/# 类似的STORES/KOL字符串替换,STORES/KOL10/8/36字符串应该是10#8#36

标签: oracleoracle11goracle10g

解决方案


with s as (select '"STORES/KOL#10/8/36#1718.00#4165570.00#119539388#PT3624496#9902001#04266#6721#PT3624496-11608091-1-55-STORES/KOL"' str from dual)
select 
replace(replace(str, '/', '#'), 'STORES#KOL', 'STORES/KOL') result_str_1,
regexp_replace(str, '(\d)/', '\1#')                         result_str_2
from s;

推荐阅读