[英]Equivalent of MySQL HEX / UNHEX function in SQL Server?
SQL Server是否具有与HEX
和UNHEX
MySQl功能相同的功能?
What are you going to do? 你会怎样做?
Something like a script generation? 像脚本生成的东西?
There might be better approaches for your issue, but you do not provide many details... 您的问题可能有更好的方法,但您没有提供很多细节......
Not quite as slim but this would work 不太苗条,但这会奏效
--This will show up like needed, but it will not be a string
SELECT CAST('abc' AS VARBINARY(MAX))
--this is the string equivalent
SELECT sys.fn_varbintohexstr(CAST('abc' AS VARBINARY(MAX)));
--This will turn the string equivalent back to varbinary
SELECT sys.fn_cdc_hexstrtobin('0x616263')
--And this will return the original string
SELECT CAST(sys.fn_cdc_hexstrtobin('0x616263') AS VARCHAR(MAX));
If you deal with UNICODE
you can check the changes if you set N'abc'
instead of 'abc'
and in den final line you'd have to convert '0x610062006300'
to NVARCHAR
. 如果您处理
UNICODE
您可以检查更改,如果您设置N'abc'
而不是'abc'
并且在最后一行中您必须将'0x610062006300'
转换为NVARCHAR
。
If you need this more often you might put this into an UDF, than it is as eays as with MySQL :-) 如果你经常需要这个,你可能会把它放到UDF中,而不是像MySQL一样:-)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.