CLR UDF returning Varbinary(MAX)(CLR UDF 返回 Varbinary(MAX))
问题描述
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)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:CLR UDF 返回 Varbinary(MAX)
- 在SQL中,如何为每个组选择前2行 2021-01-01
- 更改自动增量起始编号? 2021-01-01
- 使用 Oracle PL/SQL developer 生成测试数据 2021-01-01
- 如何将 Byte[] 插入 SQL Server VARBINARY 列 2021-01-01
- SQL 临时表问题 2022-01-01
- 如何使用 pip 安装 Python MySQLdb 模块? 2021-01-01
- 如何将 SonarQube 6.7 从 MySQL 迁移到 postgresql 2022-01-01
- 远程 mySQL 连接抛出“无法使用旧的不安全身份验证连接到 MySQL 4.1+"来自 XAMPP 的错误 2022-01-01
- 以一个值为轴心,但将一行上的数据按另一行分组? 2022-01-01
- 导入具有可变标题的 Excel 文件 2021-01-01
