为什么定义了游标在执行的时候说未定义

[复制链接]
查看11 | 回复2 | 2011-7-27 17:19:20 | 显示全部楼层 |阅读模式
declare @id int
declare @xuehaos char(20)
declare @xuehao char(20)
set @xuehao=1
declare @dianhuas char(20)
declare youbiao1 cursor for
select id,xuehao,dianhua from xuesheng
open youbiao1
fetch next from xuesheng
into @id,@xuehaos,@dianhuas
while @@fetch_status=0
begin
if @xuehao=@xuehaos
delete from xuesheng where @xuehao=@xuehaos
fetch next from youbiao1
into @id,@xuehaos,@dianhuas
end
close youbiao1
deallocate youbiao1
执行提示:
消息 16916,级别 16,状态 1,第 8 行
名为 'xuesheng' 的游标不存在。

回复

使用道具 举报

千问 | 2011-7-27 17:19:20 | 显示全部楼层
declare youbiao1 cursor for你定义的游标名字是 youbiao1 open youbiao1fetch next from xuesheng这里你从游标获取数据的时候, 指定的是 xuesheng。。。close youbiao1deallocate youbiao1把 fetch next from xuesheng修改为 fetch next from youbiao1...
回复

使用道具 举报

千问 | 2011-7-27 17:19:20 | 显示全部楼层
你定义的游标是 youbiao1 ,xuesheng是表fetch next from xuesheng 这里应该是 fetch next from youbiao1...
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行