时间:2021-07-01 10:21:17 帮助过:4人阅读
--【提取中文】
IF OBJECT_ID(‘DBO.get_Chinese‘) IS NOT NULL
DROP FUNCTION DBO.get_Chinese
GO
CREATE FUNCTION DBO.get_Chinese(@S NVARCHAR(100))
RETURNS VARCHAR(100)
AS
BEGIN
WHILE PATINDEX(‘%[^吖-座]%‘,@S) > 0
SET @S = STUFF(@S,PATINDEX(‘%[^吖-座]%‘,@S),1,N‘‘)
RETURN @S
END
GO
SELECT DBO.get_Chinese(‘turing我666QQ中国AK123‘)
--【提取数字】
IF OBJECT_ID(‘dbo.GET_NUMBER‘) IS NOT NULL
DROP FUNCTION dbo.GET_NUMBER
GO
CREATE FUNCTION dbo.GET_NUMBER(@S VARCHAR(100))
RETURNS VARCHAR(100)
AS
BEGIN
WHILE PATINDEX(‘%[^0-9]%‘,@S) > 0
BEGIN
set @s=stuff(@s,patindex(‘%[^0-9]%‘,@s),1,‘‘)
END
RETURN @S
END
GO
SELECT DBO.GET_NUMBER(‘turing我666QQ中国AK123‘)
--【提取英文】
IF OBJECT_ID(‘DBO.get_English‘) IS NOT NULL
DROP FUNCTION DBO.get_English
GO
CREATE FUNCTION DBO.get_English(@S VARCHAR(100))
RETURNS VARCHAR(100)
AS
BEGIN
WHILE PATINDEX(‘%[^a-z]%‘,@S) > 0
BEGIN
set @s=stuff(@s,patindex(‘%[^a-z]%‘,@s),1,‘‘)
END
RETURN @S
END
GO
SELECT DBO.get_English(‘turing我666QQ中国AK123‘)
SQL Server 从字符串中提取中文、英文、数字
标签:while div sql tin word select index uri har