--BASE64编码 CREATE FUNCTION [dbo].[FnBase64Encode](@src varchar(max)) RETURNS VARCHAR(max) as begin declare @bin varbinary(max) set @bin=Convert(varbinary(max), @src) return cast(N'' as xml).value('xs:base64Binary(xs:hexBinary(sql:variable("@bin")))', 'varchar(max)') end GO --BASE64解码 CREATE FUNCTION [dbo].[FnBase64Decode](@64 varchar(max)) RETURNs VARCHAR(max) AS BEGIN declare @bin varbinary(max) set @bin=cast(N'' as xml).value('xs:base64Binary(sql:variable("@64"))', 'varbinary(max)') return Convert(varchar(max),@bin) END GO -- 存储过程demo ALTER PROCEDURE p_user_register (@name nvarchar(50),@username nvarchar(50), @password nvarchar(50),@msg nvarchar(255) OUTPUT) AS BEGIN SELECT @msg=COUNT(*) FROM t_user u WHERE u.UserName = @username AND u.Password = @password; IF @msg = '1' BEGIN set @msg='username 重复,请重新注册' END ELSE BEGIN INSERT INTO t_user (UserName,Password,name,roles,token) VALUES(@username, @password,@name,'admin', dbo.FnBase64Encode(@username+@password+@name+convert(varchar(19),getdate(),120)) ) set @msg='注册成功' END END
标签:bin,username,存储,set,varchar,max,Base64,sqlserver,msg From: https://www.cnblogs.com/xfweb/p/16608264.html