問題描述
SQL CLR 用戶定義函數是否可以返回數據類型 varbinary(MAX)?
Is it possible for a SQL CLR User-Defined Function to return the data type varbinary(MAX)?
在它提到的文檔中:
標量值函數返回的輸入參數和類型可以是 SQL Server 支持的任何標量數據類型,但 rowversion、text、ntext、image、timestamp、table 或 cursor 除外."- 他們沒有提到 varbinary,但我不確定...
"The input parameters and the type returned from a scalar-valued function can be any of the scalar data types supported by SQL Server, except rowversion, text, ntext, image, timestamp, table, or cursor." - they don't mention varbinary, but I'm not sure...
我有一些來自 .NET 端的字節數組數據,我需要從 CLR 返回到 SQL Server,并且我試圖避免使用來自存儲過程的輸出參數(這就是我現在正在測試中).
I have some byte-array data from the .NET side that I need to return to SQL Server from the CLR, and I'm trying to avoid having to do it with an output parameter from a stored procedure (this is how I have it working in test now).
謝謝!
推薦答案
如果您將其定義為返回一個 SqlBytes 數據類型,這應該正確映射到 SQL Server 中的 varbinary(MAX)
.
If you define it as returning a SqlBytes data type, this should correctly map to varbinary(MAX)
in SQL Server.
[SqlFunction]
public static SqlBytes Function1()
{
return new SqlBytes(Encoding.UTF8.GetBytes("Hello world."));
}
雖然您也可以使用 SqlBinary 數據類型,如果您通過 Visual Studio 部署,它將映射到 varbinary(8000)
而不是 varbinary(MAX)
.
Whilst you can also use the SqlBinary data type, if you deploy via Visual Studio, it will be mapped onto varbinary(8000)
rather than varbinary(MAX)
.
這篇關于CLR UDF 返回 Varbinary(MAX)的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!