我想通过#######
掩盖一些SQL数据。
我正在尝试关注SQL:
SELECT
CONCAT ( SUBSTRING(email_address,1,3),
'#####' ,
SUBSTRING(email_address,LENGTH(email_address) - 2, LENGTH(email_address) )
) AS Result, REPLACE( SUBSTRING(email_address,1,3, ' ', ' ' ) as Replaced
FROM employees
表中的 email_address
列已加密或散列。我想动态地屏蔽数据(根据长度)我想只显示5个字符,因为它在中间并且全部保留在' #########' #########格式。掩蔽后不应改变长度。
表中存在的数据如:
15a97dbe57dc993847fbf18394948b8b
1so8GhueT58ked3OvsMeqHbQfIN+zyg8gGj6sQrUB6A=
答案 0 :(得分:1)
SELECT
LEFT('15a97dbe57dc993847fbf18394948b8b',5)
+ REPLICATE('#', LEN('15a97dbe57dc993847fbf18394948b8b') - 10)
+ RIGHT('15a97dbe57dc993847fbf18394948b8b', 5)
这应该得到你想要的(MSSQL)
编辑1(PostGreSQL)
SELECT CONCAT ( LEFT( bank_account_number_encrypted,5 ),
REPEAT('#', LENGTH(bank_account_number_encrypted) - 10) ,
RIGHT(bank_account_number_encrypted, 5) )
FROM employees