设为首页 加入收藏

TOP

SQL存储过程返回值
2014-11-24 07:22:42 来源: 作者: 【 】 浏览:2
Tags:SQL 存储 过程 返回

SQL存储过程返回值
先靠一下自己。
当我做多了ORACLE时,我就忘了SQL的储存过程可以返回数据集这个事实了。
。。。。。。。。。。。。。。。。
Create procedure test
@t1 int,
@t2 nvarchar(200) out
as www.2cto.com
set t2='这个是输出参数';
go
调用
declare @out_t2 nvarchar(200);
exec test 1,@out_t2;
select @out_t2;
输出:
这个是输出参数
www.2cto.com
-----
也可以定义一个接收参数,接收存储过程的成功与否的默认返回值(这会是一个整数,0 是无错误执行,其它数为错误代码!)
declare @val int;
declare @out_t2 nvarchar(200);
exec @val = test 1,@out_t2;
select @out_t2,@val;
除了这些简单参数,存储过程还可以直接返回一个数据集
www.2cto.com
create table table_2( i_key int,i_value varchar(20));
declare @d int;
set @d=1;
WHILE @d<10
begin
insert into table_2 select @d+1,cast(@d as varchar(50))+'S';
set @d = @d+1;
end;
Create procedure test
@t1 int
www.2cto.com
as
select * from table_2;
go
执行:
exec test 1;
结果,就是table_2表的集合.
作者 akuoma
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇SQLServer存储过程返回值总结 下一篇SQL Server结果集循环处理的避免..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·Java 并发工具类:提 (2025-12-25 20:25:44)
·Java面试技巧:如何 (2025-12-25 20:25:41)
·Java并发编程中的线 (2025-12-25 20:25:38)
·C 语言 - cppreferen (2025-12-25 19:50:27)
·《C 语言入门教程》 (2025-12-25 19:50:23)