存储过程的输出参数的问题

FlyingQQ 2003-11-14 01:45:11
1、我怎么在查询分析器里面查看输出参数的值?
2、我这样写会把错误代码作为输出参数传出来吗?
create procedure deleteinfo
@id int,
@Ret_Err int ='' output
as
delete talbe_info where id=@id
select @Ret_Err=@@Error
GO
...全文
68 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
zjcxc 元老 2003-11-14
  • 打赏
  • 举报
回复
在查询分析器中调用的时候,就必须先定义变量来保存输出参数的值.

如果是在程序中调用,就不必定义了.下面是VB中的调用例子:

Sub cmd()
Dim iCmd As ADODB.Command
Dim iRe&

Set iCmd = New ADODB.Command
With iCmd
.ActiveConnection = iConc 'iConc是数据库连接字符串
.CommandType = adCmdStoredProc
.CommandText = "deleteinfo"
.Parameters.Refresh
.Parameters("@id")=1
.Execute
MsgBox "处理结果:" & .Parameters("@Ret_Err")
End With
End Sub
zjcxc 元老 2003-11-14
  • 打赏
  • 举报
回复
create procedure deleteinfo
@id int,
@Ret_Err int =null output --int型的默认值你怎么用'' ?
as
delete talbe_info where id=@id
select @Ret_Err=@@Error
GO

--调用的时候
declare @re int
exec deleteinfo 1,@re out --加上out,指明是输出参数
select 结果=@re --显示取得的结果
pengdali 2003-11-14
  • 打赏
  • 举报
回复
create procedure deleteinfo
@id int,
@Ret_Err int =0 output
as
delete talbe_info where id=@id
select @Ret_Err=@@Error
GO

--调用:
declare @a int
exec deleteinfo 23,@a output
FlyingQQ 2003-11-14
  • 打赏
  • 举报
回复
declare @a int
这个是在调用存储过程的时候定义吗?
能不能在存储过程里面设置了,我只用传ID进去就可以返回错误代码呢?
txlicenhe 2003-11-14
  • 打赏
  • 举报
回复
create procedure deleteinfo
@id int,
@Ret_Err int =0 output
as
delete talbe_info where id=@id
select @Ret_Err=@@Error
GO

declare @a int
exec deleteinfo 23,@a output
Select @a

pengdali 2003-11-14
  • 打赏
  • 举报
回复
create procedure deleteinfo
@id int,
@Ret_Err int =0 output
as
delete talbe_info where id=@id
select @Ret_Err=@@Error
GO

declare @a int
exec deleteinfo 23,@a

34,874

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧