SqlServer数据库全角转换成半角
代码如下:
CREATE FUNCTION f_Convert( @str NVARCHAR(4000), --要转换的字符串 @flag bit --转换标志,0转换成半角,1转换成全角 )RETURNS nvarchar(4000) AS BEGIN DECLARE @pat nvarchar(8),@step int,@i int,@spc int IF @flag=0 SELECT @pat=N'%[!-~]%',@step=-65248, @str=REPLACE(@str,N' ',N' ') ELSE SELECT @pat=N'%[!-~]%',@step=65248, @str=REPLACE(@str,N' ',N' ') SET @i=PATINDEX(@pat COLLATE LATIN1_GENERAL_BIN,@str) WHILE @i> 0 SELECT @str=REPLACE(@str, SUBSTRING(@str,@i,1), NCHAR(UNICODE(SUBSTRING(@str,@i,1))+@step)) ,@i=PATINDEX(@pat COLLATE LATIN1_GENERAL_BIN,@str) RETURN(@str) END GO调用:update table1 set column1=dbo.f_Convert(column1,0);
相关推荐
mcvsyy 2020-07-26
maokaijiang 2020-06-14
LzHeng 2020-06-05
huanghan 2020-05-31
maokaijiang 2020-04-18
tlsmile 2020-04-14
lhxxhl 2020-04-11
maokaijiang 2020-03-27
jiong 2020-03-23
maokaijiang 2020-02-13
zbcaicai 2020-02-01
nxcjh 2020-02-01
sui 2019-12-25
OwenJi 2019-12-25
huanghan 2019-12-14