我有一些循环和条件。如果条件匹配,那么我想停止或退出存储过程。怎么做?
while @@fetch_status=0
begin
if x=0
'exit stored procedure
end
答案 0 :(得分:11)
如果您使用的是Microsoft Sql Server,则可以使用Return
Statement
while @@fetch_status=0 begin if x=0 return; end
答案 1 :(得分:4)
通过@@fetch_status
,它看起来像是你的光标循环内部,所以我会不返回,因为你将跳过自己整理。
...
if x=0
GOTO DONE
...
/* at the end of the sp */
DONE:
CLOSE @your_cur
DEALLOCATE @your_cur
答案 2 :(得分:1)
尝试使用return
while @@fetch_status=0
begin
if x=0
return
end