hive sql 实现姓名手机号证件号脱敏

需求描述

  • 姓名
    • 中文姓名
      • 2个字码最后一个字
      • 大于等于3个字,只留第一个和最后一个字
    • 英文姓名
      • 保留第一个和最后一个字符 例如 Jack.Antg 脱敏后变成J***.***g
  • 手机号
    • 11位 则保留前3位和最后4位
    • 其他位数的脱敏中部三分之一
  • 证件号
    • 大于8位,除了前后4位都脱敏
    • 小于等于8大于4 ,除了后4位都脱敏
    • 小于等于4,不脱敏

实现

姓名脱敏

case when length(name)<1 then null
		when length(name)=1 then name
           when length(name)=2 then concat(substr(name,1,1),'*')
           when length(name)>=3 then concat(substr(name,1,1),substr(regexp_replace(name,'[^.]','*'),2,length(name)-2),substr(name,-1))
end as name

证件号脱敏

case when length(id_no)<=4 then id_no
          when length(id_no) in(5,6,7,8) then concat(substr(regexp_replace(id_no,'.','*'),1,length(id_no)-4),substr(id_no,-4))
          when length(id_no)>8 then concat(substr(id_no,1,4),substr(regexp_replace(id_no,'.','*'),2,length(id_no)-8),substr(id_no,-4))
end as id_no

手机号脱敏

case 
  when length(phone)<1 then null
  when length(phone)=2 then concat(substr(phone,1,1),'*')
  when length(phone) in(3,4,5,6,7,8,9,10) then concat(substr(phone,1,cast(round(length(phone)/3.0) as int)),substr(regexp_replace(phone,'.','*'),cast(round(length(phone)/3.0) as int)+1,cast(round(length(phone)/3.0) as int)),substr(phone,-(length(phone)-2*cast(round(length(phone)/3.0) as int))))
  when length(phone)=11 then concat(substr(phone,1,3),'****',substr(phone,-4))
  when length(phone)>=12 then concat(substr(phone,1,cast(round(length(phone)/3.0) as int)),substr(regexp_replace(phone,'.','*'),cast(round(length(phone)/3.0) as int)+1,cast(round(length(phone)/3.0) as int)),substr(phone,-(length(phone)-2*cast(round(length(phone)/3.0) as int))))
end as phone
  • 6
    点赞
  • 25
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Antgeek

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值