如何查找和替换字符串列中的字符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。
我该怎么做?
在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');
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)