如果建立cursor在两个字段上,而对一个变量赋值,会抱错么?
比如说:
declare @id int
create cur1 cursor
for select id,name from student
open cur1
fetch next from cur1 into @id /* in cur1 there are two column, then fetch them into only one variable, how it will be? */
close cur1
deallocate cur1
------解决方案--------------------
应改会报错吧
服务器: 消息 16924,级别 16,状态 1,行 5
Cursorfetch: 在 INTO 列表中声明的变量数目必须与所选择的列数目匹配。
declare @id int
create cur1 cursor -- declare cur1 cursor
for select id,name from student
open cur1
fetch next from cur1 into @id /* in cur1 there are two column, then fetch them into only one variable, how it will be? */
close cur1
deallocate cur1
------解决方案--------------------
create cur1 cursor 应改为 declare cur1 cursor
数量要对应,确实要一个变量接收,应在声明时只给一个,或用两个字段组合成一个查询字段