oracle替换手机号中间的4位为*号

使用 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;
发布了422 篇原创文章 · 获赞 7 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/enthan809882/article/details/104196511