如何替换 SQL SERVER 中字符串中 x 和 y 字符之间的字符。
例如,如果我有: TEST123456 最后有 TE*****56。我不知道字符串有多长,但我知道我需要屏蔽字符串中 x 和 y 之间的字符
你可以使用REPLICATE() https://learn.microsoft.com/en-us/sql/t-sql/functions/replicate-transact-sql?view=sql-server-2017 and STUFF() https://learn.microsoft.com/en-us/sql/t-sql/functions/stuff-transact-sql?view=sql-server-2017 as:
DECLARE @String VARCHAR(20)='TEST123456',
@Start INT = 3,
@End INT = 5;
SELECT
@String AS MyString,
STUFF(@String, @Start, @End - @Start, REPLICATE('*', @End - @Start)) AS Mask;
当你说“我不知道这根绳子到底有多长”, the REPLICATE()
函数将根据以下条件返回星号“*”@Start
and @End
你提供。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)