答案 0 :(得分:0)
您可以使用以下示例并根据需要进一步扩展,
DECLARE @source VARBINARY(max)
,@encoded VARCHAR(max)
,@decoded VARBINARY(max)
SET @source = convert(VARBINARY(max), 'ForBase64')
SET @encoded = cast('' AS
XML).value('xs:base64Binary(sql:variable("@source"))', 'varchar(max)')
SET @decoded = cast('' AS
XML).value('xs:base64Binary(sql:variable("@encoded"))', 'varbinary(max)')
SELECT convert(VARCHAR(max), @source) AS source_varchar
,@source AS source_binary
,@encoded AS encoded
,@decoded AS decoded_binary
,convert(VARCHAR(max), @decoded) AS decoded_varchar
输出是,
source_varchar source_binary encoded decoded_binary decoded_varchar
------------------------------------------------------------------------------------------------
ForBase64 0x466F72426173653634 Rm9yQmFzZTY0 0x466F72426173653634 ForBase64