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
SQL Server Base64函数
最新推荐文章于 2022-05-06 14:31:18 发布