sql-server – 是否可以在SQL CLR用户定义的类型中创建表值*方法*?
|
我有一个CLR UDT,它将从表值方法ala xml.nodes()中受益匪浅: -- nodes() example,for reference:
declare @xml xml = '<id>1</id><id>2</id><id>5</id><id>10</id>'
select c.value('.','int') as id from @xml.nodes('/id') t (c)
我想为我的UDT类似的东西: -- would return tuples (1,4),(1,5),6)....(1,20) declare @udt dbo.FancyType = '1.4:20' select * from @udt.AsTable() t (c) 有人有任何经验吗?任何帮助将不胜感激.我已经尝试了一些事情,他们都失败了.我已经找到了文档和示例,没有找到. 是的,我知道我可以创建使用UDT作为参数的表值UDF,但我希望将所有内容捆绑在单一类型的OO样式中. 编辑 Russell Hart发现了the documentation states that table-valued methods are not supported,并修复了我的语法以产生预期的运行时错误(见下文). 在VS2010中,在创建了一个新的UDT之后,我在结构定义的末尾添加了这个: [SqlMethod(FillRowMethodName = "GetTable_FillRow",TableDefinition = "Id INT")]
public IEnumerable GetTable()
{
ArrayList resultCollection = new ArrayList();
resultCollection.Add(1);
resultCollection.Add(2);
resultCollection.Add(3);
return resultCollection;
}
public static void GetTable_FillRow(object tableResultObj,out SqlInt32 Id)
{
Id = (int)tableResultObj;
}
这样可以成功构建和部署.但是在SSMS中,我们会按预期的方式得到一个运行时错误(如果不是word-for-word): -- needed to alias the column in the SELECT clause,rather than after the table alias. declare @this dbo.tvm_example = '' select t.[Id] as [ID] from @this.GetTable() as [t] Msg 2715,Level 16,State 3,Line 2 Column,parameter,or variable #1: Cannot find data type dbo.tvm_example. Parameter or variable '@this' has an invalid data type. 所以,似乎这是不可能的.即使有可能,由于在SQL Server中更改CLR对象的限制,这可能不是明智的. 也就是说,如果有人知道要克服这个特殊的限制,我会相应地提出一个新的赏金. 解决方法您已经将列表别名,而不是列.尝试,declare @this dbo.tvm_example = '' select t.[Id] as [ID] from @this.GetTable() as [t] 根据文档http://msdn.microsoft.com/en-us/library/ms131069(v=SQL.100).aspx#Y4739,对于不正确的类型,这应该会导致另一个运行时错误.
他们可能避免支持这种方法.如果使用方法更新更改程序集,则可能会导致UDT列中的数据出现问题. xml节点方法不会改变,所以它不会受到相同的实现限制. 希望这能帮助彼得,祝你好运. (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- sql – 有没有替代MULTISET运算符,以避免子查询?
- sql – 为什么Django显式地在唯一字段上创建索引
- sql-server – SQL Server – 基于GUID的PK是支持基于租户的
- 使用SQL Server数据库嵌套子查询的方法
- mssql自动备份及自动清除日志文件服务器设置
- .net – 在SQL Server上执行用户定义函数时出现System.Secu
- MySQL分页技术、6种分页方法总结
- SQL Server2000 卸载后重新安装时不能安装的解决办法
- CentOS 7 x64下Apache+MySQL(Mariadb)+PHP56的安装教程详解
- 数据库设计 – 具有快速(1s)读取查询性能的大型( 22万亿项)
