T-SQL函数可以返回用户定义的表类型吗? [英] Can T-SQL function return user-defined table type?

查看:172
本文介绍了T-SQL函数可以返回用户定义的表类型吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我自己的类型:

$ $ p $ CREATE TYPE MyType AS TABLE

foo INT

以及将它作为参数接收的函数:

  CREATE FUNCTION测试

@in MyType READONLY

RETURNS @return MyType
AS
...

是否可以返回 MyType TABLE 重复MyType的结构:

$ p $ CREATE FUNCTION测试

@in MyType READONLY

RETURNS @return TABLE(foo INT)
AS
...

解决方案

我了解微软的这里的MSDN文章,那些用户定义的表类型只是可用作存储过程或存储函数的只读参数

不幸的是,它没有提及任何可以从用户定义函数返回的东西 - 所以我想你是对的 - 这是不可能的至少不是现在)。


I have my own type:

CREATE TYPE MyType AS TABLE
(
    foo INT
)

and a function receiving it as a parameter:

CREATE FUNCTION Test
(
    @in MyType READONLY
)
RETURNS @return MyType
AS
...

can it return MyType or only TABLE repeating MyType's structure:

CREATE FUNCTION Test
(
    @in MyType READONLY
)
RETURNS @return TABLE (foo INT)
AS
...

?

解决方案

As far as I understand Microsoft's MSDN article here, those user-defined table types are only available as read-only parameters to stored procedures or stored functions.

It doesn't mention anything that they could be used to be returned from a user-defined function, unfortunately - so I guess you're right - it's not possible (at least not now).

这篇关于T-SQL函数可以返回用户定义的表类型吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆