T-SQL函数可以返回用户定义的表类型吗? [重复]

时间:2021-11-23 01:30:02

This question already has an answer here:

这个问题在这里已有答案:

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:

它可以返回MyType还是只返回重复MyType结构的表:

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

?

1 个解决方案

#1


15  

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.

据我了解Microsoft的MSDN文章,这些用户定义的表类型仅作为存储过程或存储函数的只读参数提供。

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

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

#1


15  

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.

据我了解Microsoft的MSDN文章,这些用户定义的表类型仅作为存储过程或存储函数的只读参数提供。

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

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