SQL Server Base64函数


IF OBJECT_ID(N'dbo.c_GetUTF8Code') IS NOT NULL
    DROP FUNCTION dbo.c_GetUTF8Code;
GO

CREATE FUNCTION [dbo].[c_GetUTF8Code]  
(
    @char Nchar
)
RETURNS int

AS

--UTF8转码

BEGIN

 Declare @Code int
 Select @Code=Cast(Unicode(@char) as int)
 Declare @Utf8Code int
 Set @Utf8Code=0
 if(@Code<128)
 begin
  --0-127
  --0000-007F
  --0xxxxxxx
  --01100010 Unocide
  --01100010 UTF-8
  Set @Utf8Code=@Code 
 end
 else if(@Code>127 and @Code<2048)
 begin
  --128-2047
  --0080-07FF
  --110xxx xx10xx xxxx
  --110  7      F    F
  Declare @C1 int
  Declare @C2 int
  Declare @C3 int
  Select @C1=@Code/0x100 
  Select @C2=(@Code%0x100)/0x10
  Select @C3=@Code%0x10
  Select @Utf8Code=0xC080+0x400*@C1+0x100*(@C2/4)+0x10*(@C2%4)+@C3
 end
 else if(@Code>2047 and @Code<65536)
 begin
  --2047-65535
  --0110 0010 0001 0001
  --1110 xxxx 10xx xxxx 10xx xxxx
  --1110 0110 1000 1000 1001 0001
  Declare @C11 int
  Declare @C12 int
  Declare @C13 int
  Declare @C14 int
  Select @C11=@Code/0x1000
  Select @C12=(@Code%0x1000)/0x100
  Select @C13=(@Code%0x100)/0x10
  Select @C14=@Code%0x10
  Select @Utf8Code=0xE08080+0x10000*@C11+0x400*@C12+0x100*(@C13/4)+0x10*(@C13%4)+@C14 
 end
 return @Utf8Code
End

GO

-------加密函数[dbo].[base64_utf8encode]----

IF OBJECT_ID(N'dbo.base64_utf8encode') IS NOT NULL
    DROP FUNCTION dbo.base64_utf8encode;
GO
 
CREATE FUNCTION [dbo].[base64_utf8encode]  
(  
 @plain_text varchar(max)  
)  

RETURNS varchar(max)  

AS BEGIN
--Base64解密
 DECLARE @output varchar(max)
 DECLARE @block_start integer
 DECLARE @map char(64)  
 SET @map='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/' 
 SET @output=''
 SE

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值