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

发布于 2024-09-11 07:23:09 字数 347 浏览 4 评论 0原文

假设我有一些返回结果集的存储过程(并且我无法更改它):

create procedure test_procedure
as
begin

    select 1

end

我知道我可以将结果集插入表中,因此它将对调用代码隐藏:

declare @t table(i int)

insert into @t
exec test_procedure

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

已更新

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

放我走吧 2024-09-18 07:23:09

不,没有其他解决方案。但是,您应该重构您的过程以仅执行您需要的操作。如果您需要其他调用的输出,请尝试将过程分成两个。

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.

别挽留 2024-09-18 07:23:09

使用可选的输出参数。

或使用下面的情况

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

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

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.

ゞ记忆︶ㄣ 2024-09-18 07:23:09

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

您无法轻松地通过该输出参数返回完整的结果集,但您可以以您选择的格式返回一些分隔数据。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文