SQLSERVER 2000 存储过程例子

create table test(id int primary key ,name char ( 10 ))

insert into test values ( 1 , ' test1 ' )
insert into test values ( 2 , ' test2 ' )
insert into test values ( 3 , ' test3 ' )
insert into test values ( 4 , ' test4 ' )

1 、返回结果集

create procedure return_result
as
select * from test

exec return_result
-- 调用
--
id       name
--
1     test1     
--
2     test2     
--
3     test3     
--
4     test4     

2 、输入参数和输出参数

create procedure input_output
@id int ,
@name char ( 10 ) output
as
begin
select @name = name from test where id = @id
end

-- 调用
declare @name char ( 10 )
exec input_output 1 , @name output
select @name name
-- 输出结果
--
name
--
test1

3 、返回值

-- 每个存储过程都可以以一个return语句返回一个整型(integer)的值
alter procedure return_value
@id int
as
begin
declare @count int     -- 只能返回整型的值
select @count = count ( * ) from test where id = @id
return @count
end


-- 调用
declare @count char ( 10 )
exec @count = return_value 1
select @count shuliang
-- 结构
--
shuliang
--
1
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值