標籤:object ike class string lse abc ret creat byte
Sqlserver UrlEncode
if exists (select * from dbo.sysobjects where id = object_id(N‘[dbo].[UrlEncode]‘) and xtype in (N‘FN‘, N‘IF‘, N‘TF‘))-- 刪除函數drop function [dbo].[UrlEncode]GOCREATE FUNCTION dbo.UrlEncode(@URL varchar(3072))RETURNS varchar(3072)ASBEGIN DECLARE @count int,@char varchar(2),@i int,@bytes binary(2),@low8 int,@high8 intDECLARE @URLEncode varchar(3000) ;SET @count = LEN(@URL)SET @i = 1SET @URLEncode = ‘‘WHILE (@i <= @count)BEGIN SET @char = SUBSTRING(@URL,@i,1) IF @char LIKE ‘[-A-Za-z0-9()‘‘*._!]‘ AND DATALENGTH(@char) = 1 SET @URLEncode = @URLEncode + @char ELSE BEGIN IF DATALENGTH(@char) = 1 BEGIN SET @URLEncode = @URLEncode + ‘%‘ + SUBSTRING(‘0123456789ABCDEF‘,(ASCII(@char) / 16 + 1),1) SET @URLEncode = @URLEncode + SUBSTRING(‘0123456789ABCDEF‘,(ASCII(@char) % 16 + 1),1) END ELSE BEGIN SET @bytes = CONVERT(binary,@char) SET @high8 = (0xFF00 & CAST(@bytes AS int))/256 SET @low8 = 0x00FF & CAST(@bytes AS int) SET @URLEncode = @URLEncode + ‘%‘ + SUBSTRING(‘0123456789ABCDEF‘,(@high8 / 16 + 1),1) SET @URLEncode = @URLEncode + SUBSTRING(‘0123456789ABCDEF‘,(@high8 % 16 + 1),1) SET @URLEncode = @URLEncode + ‘%‘ + SUBSTRING(‘0123456789ABCDEF‘,(@low8 / 16 + 1),1) SET @URLEncode = @URLEncode + SUBSTRING(‘0123456789ABCDEF‘,(@low8 % 16 + 1),1) END END SET @i = @i + 1 END RETURN @URLEncode;END
Sqlserver UrlEncode