循环当中应该是:fetch next from student_cursor into @name,@st_id

解决方案 »

  1.   

    use xsqk
    declare @name char(20),@st_id char(20)
    declare student_cursor cursor for
       select 姓名,学号 from xs
    open student_cursor
    fetch next from student_cursor into @name,@st_id
    select @name,@st_id
    while @@fetch_status=0
       begin
           fetch next from student_cursor into @name,@st_id
    -------------------------------------^^^^^^^^^^^^^^^^^
           select @name,@st_id
       end
    close student_cursor
    deallocate student_cursor
      

  2.   

    循环当中是:fetch next from student_cursor into @name,@st_id
    结果是对的。
    但是循环当中是:fetch next from student_cursor 结果就有问题了。也能将表中记录从头显示,只是显示的是:第一条记录,第二条,第一条,第三条,第一条,第四条。这是为什么?
      

  3.   

    当循环当中是:fetch next from student_cursor into @name,@st_id时数据会被放入@name,@st_id
    而当循环当中是:fetch next from student_cursor时游标会自动显示数据,
    而@name,@st_id中数据没变你循环中的“select @name,@st_id”也会显示但一直显示的是第一条数据,所以