本文共 1095 字,大约阅读时间需要 3 分钟。
全角转半角:
--full2half /*全角(Fullwidth)转换为半角(Halfwidth)*/CREATE FUNCTION [dbo].[full2half](@String nvarchar(max))RETURNS nvarchar(max)ASBEGIN DECLARE @chr nchar(1) DECLARE @i int SET @String = REPLACE(@String,N' ',N' ') SET @i = PATINDEX(N'%[!-~]%' COLLATE Latin1_General_BIN,@String) WHILE @i > 0 BEGIN SET @chr = SUBSTRING(@String,@i,1) SET @String = REPLACE(@String,@chr,NCHAR(UNICODE(@chr)-65248)) SET @i = PATINDEX(N'%[!-~]%' COLLATE Latin1_General_BIN,@String) END RETURN @StringENDGO
半角转全角:
/*半角(Halfwidth)转换为全角(Fullwidth)*/CREATE FUNCTION [dbo].[half2full](@String nvarchar(max))RETURNS nvarchar(max)ASBEGIN DECLARE @chr nchar(1) DECLARE @i int SET @String = REPLACE(@String,N' ',N' ') SET @i = PATINDEX(N'%[!-~]%' COLLATE Latin1_General_BIN,@String) WHILE @i > 0 BEGIN SET @chr = SUBSTRING(@String,@i,1) SET @String = REPLACE(@String,@chr,NCHAR(UNICODE(@chr)+65248)) SET @i = PATINDEX(N'%[!-~]%' COLLATE Latin1_General_BIN,@String) END RETURN @StringENDGO
转载于:https://blog.51cto.com/alun51cto/2056052