1.创建存储过程,将参数avg设置为引用参数,可以对参数有反馈作用

create procedure sp_goods_price_avg 
(
@name nvarchar(255),
@avg float output
)
as
select @avg=AVG(price) from goods where gname=@name
go

2.执行存储过程,传入参数时也是用output关键字

declare @avg float;
exec sp_goods_price_avg '电视', @avg output;
print @avg;
05-26 17:05