避免从存储过程中返回结果集

时间:2021-09-09 10:06:13

Assume I have some stored procedure (and I can't change it) which is returning a result set:

假设我有一个存储过程(我不能更改它),它返回一个结果集:

create procedure test_procedure
as
begin

    select 1

end

I know that I can insert result set into table, so it would be hidden to the calling code:

我知道我可以将结果集插入到表中,这样它就会隐藏在调用代码中:

declare @t table(i int)

insert into @t
exec test_procedure

Are there any other ways to hide returning result set from the calling code?

是否有其他方法隐藏从调用代码返回的结果集?

Updated

更新

It looks like I've been a bit confusing. I'm looking only for T-SQL answers (not .NET ones).

看起来我有点困惑。我只寻找T-SQL的答案(而不是。net的)。

3 个解决方案

#1


3  

No, there is no other solution. However, you should refactor your procedure to do only what you need. If you need the output for other calls, try to split the procedure into two.

不,没有别的办法了。但是,您应该重构您的过程,只做您需要做的事情。如果您需要其他调用的输出,请尝试将过程分成两个。

#2


1  

Use optional Output Parameter.

使用可选的输出参数。

or use below case

或使用下面的情况

Create procedure Check @c int
as
begin
if @c = 1
    select 1
else
    print 1 
end

write any condition that will satisfy and that returns you specified values. use that parameter as optional so no other change in your procedure will come.

编写任何满足且返回指定值的条件。将该参数作为可选参数使用,这样就不会出现过程中的其他更改。

#3


0  

Would you rather try to return your data through an output parameter, and return a status code as the procedure's return value?

您愿意尝试通过输出参数返回数据,并返回状态码作为过程的返回值吗?

You couldn't easily return a full resultset through that output parameter, but you could return some delimited data in a format of your choosing.

不能通过输出参数轻松返回完整的resultset,但可以返回一些带分隔符的数据,格式由您自己选择。

#1


3  

No, there is no other solution. However, you should refactor your procedure to do only what you need. If you need the output for other calls, try to split the procedure into two.

不,没有别的办法了。但是,您应该重构您的过程,只做您需要做的事情。如果您需要其他调用的输出,请尝试将过程分成两个。

#2


1  

Use optional Output Parameter.

使用可选的输出参数。

or use below case

或使用下面的情况

Create procedure Check @c int
as
begin
if @c = 1
    select 1
else
    print 1 
end

write any condition that will satisfy and that returns you specified values. use that parameter as optional so no other change in your procedure will come.

编写任何满足且返回指定值的条件。将该参数作为可选参数使用,这样就不会出现过程中的其他更改。

#3


0  

Would you rather try to return your data through an output parameter, and return a status code as the procedure's return value?

您愿意尝试通过输出参数返回数据,并返回状态码作为过程的返回值吗?

You couldn't easily return a full resultset through that output parameter, but you could return some delimited data in a format of your choosing.

不能通过输出参数轻松返回完整的resultset,但可以返回一些带分隔符的数据,格式由您自己选择。