我刚才又用一个简单的例子试了一下,果然如此。
select * from test
declare @col1 integer
declare @col2 integerdeclare mycursor cursor for
select * from testopen mycursor
fetch next from mycursor into @col1,@col2
print @col1while (@@fetch_status=0)begin
fetch next from mycursor into @col1,@col2
print @col1
endclose mycursor
deallocate mycursortest表一共有三行,最后的输出结果却有四行。
select * from test
declare @col1 integer
declare @col2 integerdeclare mycursor cursor for
select * from testopen mycursor
fetch next from mycursor into @col1,@col2
print @col1while (@@fetch_status=0)begin
fetch next from mycursor into @col1,@col2
print @col1
endclose mycursor
deallocate mycursortest表一共有三行,最后的输出结果却有四行。
declare @col1 integer
declare @col2 integerdeclare mycursor cursor for
select * from testopen mycursor
fetch next from mycursor into @col1,@col2
while (@@fetch_status=0)
begin
print @col1
fetch next from mycursor into @col1,@col2endclose mycursor
deallocate mycursor
select * from test
open mycursor
fetch next from mycursor into @col1,@col2
while (@@fetch_status=0)
begin
print @col1
fetch next from mycursor into @col1,@col2 //处理完一条后取下一条
endclose mycursor
deallocate mycursor