相关文章推荐
温柔的小蝌蚪  ·  CEdit 类 | Microsoft Learn·  1 周前    · 
打盹的木瓜  ·  URL类方法源码解读_url ...·  8 月前    · 
气势凌人的稀饭  ·  android - How to ...·  1 年前    · 
玉树临风的口罩  ·  Pywinauto之Windows UI ...·  1 年前    · 
大鼻子的奔马  ·  (二)、FFmpeg ...·  1 年前    · 

一、先查找,再替换

select replace('陈宏宏',substr('陈宏宏',2,1),'*') as name from dual;

注意: 此种方法通过对第2个字符进行替换,如果名字为叠名,则会发生上述误替换情况;

select substr('陈宏宏',1,1)||'*'||substr('陈宏宏',3,1) as name from dual;

三、使用regexp_replace进行精准替换

select regexp_replace('陈宏宏','(.)','*',2,1) as name from dual;

注意: regexp_replace支持使用正则表达式对字符串进行替换,该语句解释为从第2个字符开始,取任意1个字符,替换为*;

四、完整的替换代码

create table temp_cwh_002 as
select a.acc_nbr,
       a.act_city,
       a.city_name,a.number1,
       a.number2,
       case when length(a.cust_name) = 2 then regexp_replace(cust_name,'(.)','*',2,1)
            when length(a.cust_name) = 3 then regexp_replace(cust_name,'(.)','*',2,1)
            when length(a.cust_name) = 4 then regexp_replace(cust_name,'(.)','*',3,1)
       else cust_name end cust_name,
       a.acc_nbr2,
       a.param_value
from temp_cwh_001 a
where length(a.cust_name) <= 4

END 2019-01-02 16:44:13