您的位置:澳门新葡8455最新网站 > 数据库管理 > Sqlserver UrlEncode

Sqlserver UrlEncode

发布时间:2019-12-09 15:19编辑:数据库管理浏览(190)

    澳门新葡萄京娱乐场,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]
    GO
    CREATE FUNCTION dbo.UrlEncode(@URL varchar(3072))
    RETURNS varchar(3072)
    AS
    BEGIN 
     DECLARE @count int,
    @char varchar(2),
    @i int,
    @bytes binary(2),
    @low8 int,
    @high8 int
    
    DECLARE @URLEncode varchar(3000) ;
    SET @count = LEN(@URL)
    SET @i = 1
    SET @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
    

     

    本文由澳门新葡8455最新网站发布于数据库管理,转载请注明出处:Sqlserver UrlEncode

    关键词:

上一篇:没有了

下一篇:没有了