数据库
首页 > 数据库> > string to base64 or base64 to string in ms sql server

string to base64 or base64 to string in ms sql server

作者:互联网

代码如下:

源代码:

CREATE FUNCTION [dbo].[svf_StringToBase64] 
(
    @input NVARCHAR(MAX)
)
RETURNS NVARCHAR(MAX)
AS
BEGIN   
  RETURN (SELECT CAST(@input AS VARBINARY(MAX)) FOR XML PATH(''))
END
GO

CREATE FUNCTION [dbo].[svf_Base64ToString] 
(
    @input NVARCHAR(MAX)
)
RETURNS NVARCHAR(MAX) 
AS
BEGIN 
  RETURN (SELECT CAST(CAST(@input AS XML).value('.','VARBINARY(MAX)') AS NVARCHAR(MAX)))
END
GO
Source Code

 

 

实例:

 

源代码:

SELECT [dbo].[svf_StringToBase64] (N'insus.net@中国')
GO

SELECT [dbo].[svf_Base64ToString] (N'aQBuAHMAdQBzAC4AbgBlAHQAQAAtTv1W')
GO
Source Code

 

标签:string,dbo,MAX,base64,server,GO,input,NVARCHAR,SELECT
来源: https://www.cnblogs.com/insus/p/16372528.html