使用 replace(phone,substr(phone,4,4),'****')
即可。
如下sql:
SELECT
username,
REPLACE ( phone, substr( phone, 4, 4 ), '****' ) AS phone
FROM
USER;
还有一种方式 substr(username,1,3)||'****'||substr(username,-4,4)
,
sql如下:
update
user set username
=substr(username,1,3)||'****'||substr(username,-4,4) where username is not null;