查找和替换字符

问题描述 投票:0回答:1

如何查找和替换字符串列中的字符RS和OS ===> D,LS和IS ====> SECTION_ID

需要输出

1-LS-1991      1-P-1991
1-IS-1991      1-P-1991
1-RS-1991      1- D- 1991
1-OS-1991      1-D-1991

我有一个列部分ID,其中包含1-LS-1991、1-IS-1991、1-RS-1991、1-OS-1991,并且所有这些ID的多个记录我想用P替换LS,用D。

我该怎么做?

sql oracle plsqldeveloper
1个回答
0
投票

在MySQl中,如下使用,>>

update table_name replace SET column_name = REPLACE(column_name ,'RS','D');update table_name replace SET column_name = REPLACE(column_name ,'OS','D');update table_name replace SET column_name = REPLACE(column_name ,'LS','P');update table_name replace SET column_name = REPLACE(column_name ,'IS','P');


0
投票
select regexp_replace(regexp_replace(LP, '(RS)|(OS)', 'D'), '(LS)|(IS)', 'P') as replaced_input
from
(select '1-LS-1991' as LP from dual
union all
select '1-RS-1991' as LP from dual
union all
select '1-IS-1991' as LP from dual
union all
select '1-OS-1991' as LP from dual)
© www.soinside.com 2019 - 2024. All rights reserved.