使用 SQL 查询隐藏电子邮件地址中的字符 [英] Hide characters in email address using an SQL query

查看:33
本文介绍了使用 SQL 查询隐藏电子邮件地址中的字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常具体的业务需求,要在从 SQL 返回时隐藏电子邮件地址中的某些字符,而我已经达到了使用 SQL 实现这一目标的能力的极限.我想知道是否有人能指出我正确的方向.本质上,我的业务要求如下:

I have a very specific business requirement to hide certain characters within an email address when returned from SQL and I have hit the limit of my ability with SQL to achieve this. I was wondering if someone out there would be able to point me in the right direction. Essentially, my business is asking for the following:

test@email.com 变成 t*\*t@e**l.com

thislong@emailaddress.com 变成 t******h@e**********s.com

我知道如果@之前或之后的电子邮件的任何部分少于 3 个字符,那么这将不起作用,但我打算检查这一点并适当地处理它.我尝试了 SUBSTRING、STUFF、LEFT/RIGHT 等的混合,但我不能完全正确.

I am aware that if either portion of the email before of after the @ are less than 3 characters, then this won't work, but I intend on checking for this and dealing with it appropriately. I have tried a mixture of SUBSTRING, STUFF, LEFT/RIGHT etc but I can't quite get it right.

推荐答案

非常有趣且很难生成通用解决方案试试这个

Very interesting and very much tough to generate generic solution try this

这可能对你有帮助

DECLARE @String VARCHAR(100) = 'sample@gmail.com'

SELECT STUFF(STUFF(@STring,
                   CHARINDEX('@',@String)+2,
                   (CHARINDEX('.',@String, CHARINDEX('@',@String))-CHARINDEX('@',@String)-3),
                   REPLICATE('*',CHARINDEX('.',@String, CHARINDEX('@',@String))-CHARINDEX('@',@String)))
               ,2
               ,CHARINDEX('@',@String)-3
               ,REPLICATE('*',CHARINDEX('@',@String)-3))

输出将是

s****e@g******l.com

thislong@emailaddress.com 的类似方式

Similar way for thislong@emailaddress.com

输出将是

t******g@e*************s.com

这篇关于使用 SQL 查询隐藏电子邮件地址中的字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆