varbinary to string on SQL Server(SQL Server 上的 varbinary 到字符串)
问题描述
如何以人类可读的形式将列值从 varbinary(max) 转换为 varchar?
How to convert a column value from varbinary(max) to varchar in human-readable form?
推荐答案
将 varbinary 转换为 varchar"可能意味着不同的事情.
"Converting a varbinary to a varchar" can mean different things.
如果 varbinary 是 SQL Server 中字符串的二进制表示(例如通过直接转换为 varbinary 或从 DecryptByPassPhrase 或 DECOMPRESS 函数)你可以 CAST 它
If the varbinary is the binary representation of a string in SQL Server (for example returned by casting to varbinary directly or from the DecryptByPassPhrase or DECOMPRESS functions) you can just CAST it
declare @b varbinary(max)
set @b = 0x5468697320697320612074657374
select cast(@b as varchar(max)) /*Returns "This is a test"*/
这等效于使用带有 0 样式参数的 CONVERT.
This is the equivalent of using CONVERT with a style parameter of 0.
CONVERT(varchar(max), @b, 0)
其他样式参数可与 CONVERT 一起用于其他答案中指出的不同要求.
Other style parameters are available with CONVERT for different requirements as noted in other answers.
这篇关于SQL Server 上的 varbinary 到字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:SQL Server 上的 varbinary 到字符串
基础教程推荐
- 将 SQL Server DateTime 列迁移到 DateTimeOffset 2021-01-01
- 在 SQL 中连接多个表 2021-01-01
- 无法解决整理冲突 2021-01-01
- SQL:使用来自具有相同列名的两个表中的数据... 2021-01-01
- SQL Server 实例在登录协商期间返回无效或不受支持的协议版本 2021-01-01
- 需要 MySQL 5.1 中的抽象触发器来更新审计日志 2021-01-01
- 如何使用 mysql.connector 禁用查询缓存 2022-01-01
- SSMS 中的权限问题:“对象 'extended_properties'、数据库 'mssqlsystem_resource'、... 错误 229)上的 SELECT 权限被拒绝" 2022-01-01
- 是否可以执行按位分组功能? 2021-01-01
- SQL 效率:WHERE IN 子查询 vs. JOIN 然后 GROUP 2021-01-01
