从字符串里提取特殊字符

/*
应用场景:从字符串里提取特殊字符
*/
--提取数字
DECLARE @STRING VARCHAR(200)
SET @STRING='今KFA天KlK在F1254下66FaDFA雨,FKLjFDSA8你97知道8854fAOE么I?UQRQ'
WHILE @STRING LIKE '%[^0-9]%'
BEGIN
SET @STRING=STUFF(@STRING,PATINDEX('%[^0-9]%',@STRING),1,'')
END
SELECT @STRING
GO
--提取汉字
DECLARE @STRING VARCHAR(200)
SET @STRING='今KFA天KlK在F1254下66FaDFA雨,FKLjFDSA8你97知道8854fAOE么I?UQRQ'
WHILE @STRING LIKE '%[0-9 a-z]%'
BEGIN
SET @STRING=STUFF(@STRING,PATINDEX('%[0-9 a-z]%',@STRING),1,'')
END
SELECT @STRING
GO
--提取字母
DECLARE @STRING VARCHAR(200)
SET @STRING='今KFA天KlK在F1254下66FaDFA雨,FKLjFDSA8你97知道8854fAOE么I?UQRQ'
WHILE @STRING LIKE '%[^a-z]%'
BEGIN
SET @STRING=STUFF(@STRING,PATINDEX('%[^a-z]%',@STRING),1,'')
END
SELECT @STRING
GO

你可能感兴趣的:(MSSQL)