Sql Oracle中的REGEXP\u替换
我需要使用REGEXP_REPLACE执行以下操作:Sql Oracle中的REGEXP\u替换,sql,oracle,regexp-replace,Sql,Oracle,Regexp Replace,我需要使用REGEXP_REPLACE执行以下操作: If word starts with 'ABCD' then replace first four(4) chars with 'FFFF' else If word starts with 'XYZ' then replace first three(3) chars with 'GGG' 如何使用REGEXP\u REPLACE执行条件替换?您可以使用大小写和字符串操作: select (case when word li
If word starts with 'ABCD' then replace first four(4) chars with 'FFFF'
else
If word starts with 'XYZ' then replace first three(3) chars with 'GGG'
如何使用REGEXP\u REPLACE执行条件替换?您可以使用
大小写和字符串操作:
select (case when word like 'ABCD%'
then 'FFFF' || substr(word, 5)
when word like 'XYZ%'
then 'GGG' || substr(word, 4)
else word
end) as new_word
如果必须是REGEXP\u REPLACE
,则必须组合两个函数调用:
REGEXP_REPLACE(
REGEXP_REPLACE(word,'^ABCD','FFFF')
,'^XYZ', 'GGG')
但是我想说的是Gordon的案例方法…使用REGEXP\u是问题陈述的一部分,还是您想要提供的解决方案的一部分?最好的答案(由戈登·林诺夫给出)并不使用它。