题目是:使用OUTPUT的返回参数编写存储过程proc_stu,返回两个参数@name和@address代表了学生姓名和家庭住址。并调用此过程!
create proc proc_stu
(
@s_id char(2),
@name char(8) output,
@address varchar(60) output
)
as
set @name=(select s_name from stu_info where s_id=@s_id)
set @address=(select s_addr from stu_info where s_id=@s_id)
return
go
declare @return_name char(8)
declare @return_addr varchar(60)
exec proc_stu '0702301101',@return_name output,@return_addr output
select @return_name as '名称',@return_addr as '地址'
go
为什么查不出结果呢?
数据库表中的结果是
stu_info 表中的数据为 s_id 0702301101
s_name 李庭浩
s_addr 广东省广州市
怎么我查出来的结果为空呢?
试试下面的代码:
select @names=_name from stu_info where s_id=@s_id
select @address=s_addr from stu_info where s_id=@s_id