SQL存储过程返回值

SQL存储过程返回值先靠一下自己 nbsp nbsp nbsp nbsp nbsp 当我做多了 ORACLE 时 我就忘了 SQL 的储存过程可以返回数据集这个事实了 nbsp nbsp nbsp nbsp Create nbsp procedure nbsp test nbsp nbsp nbsp nbsp t1int nbsp nbsp nbsp nbsp t2nvarchar 200 outas nbsp nbsp nbsp sett2 这个是输出参数 go nbsp 调用 nbsp declare out t2

先靠一下自己。

      当我做多了ORACLE时,我就忘了SQL的储存过程可以返回数据集这个事实了。

     。。。。。。。。。。。。。。。。

Create procedure  test

     @t1 int,

     @t2 nvarchar(200) out

as

    set t2=’这个是输出参数’;

go

 

调用

 declare @out_t2   nvarchar(200);

exec test 1,@out_t2;

select @out_t2;

输出:

 这个是输出参数

------

也可以定义一个接收参数,接收存储过程的成功与否的默认返回值(这会是一个整数,0 是无错误执行,其它数为错误代码!)

declare @val  int;

declare @out_t2   nvarchar(200);

exec @val = test 1,@out_t2;

select @out_t2,@val;

除了这些简单参数,存储过程还可以直接返回一个数据集

 

Create procedure  test

     @t1 int

as

    select * from table_2;

go

执行:

exec test 1;

结果,就是table_2表的集合.

 

 

 

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/176599.html原文链接:https://javaforall.net

(0)
上一篇 2026年3月26日 下午9:32
下一篇 2026年3月26日 下午9:32


相关推荐

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号