簡體   English   中英

相當於SQL Server中的MySQL HEX / UNHEX函數?

[英]Equivalent of MySQL HEX / UNHEX function in SQL Server?

SQL Server是否具有與HEXUNHEX MySQl功能相同的功能?

你會怎樣做?

像腳本生成的東西?

您的問題可能有更好的方法,但您沒有提供很多細節......

不太苗條,但這會奏效

--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));

一個提示

如果您處理UNICODE您可以檢查更改,如果您設置N'abc'而不是'abc'並且在最后一行中您必須將'0x610062006300'轉換為NVARCHAR

另一個提示

如果你經常需要這個,你可能會把它放到UDF中,而不是像MySQL一樣:-)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM