SQL中什么时候需要使用游标?使用游标的步骤

RT 请详细点描述    

第1个回答  2011-11-20
游标 就是打开的记录集;
当需要轮询许多记录进行处理的时候,就需要使用游标。
例如:
DECLARE cursor_CallQueue CURSOR FOR
SELECT registerno,waitingno from morn_cqqueue where calling=0 order by waitingno
OPEN cursor_CallQueue
FETCH NEXT FROM cursor_CallQueue into @registerno,@waitingno --取出当前行数据到变量
WHILE @@FETCH_STATUS = 0 --以游标没有结束建立循环
begin
--程序处理块
FETCH NEXT FROM cursor_CallQueue into @registerno,@waitingno --取出下一行
end ;
CLOSE cursor_CallQueue
DEALLOCATE cursor_CallQueue -- '删除游标引用
相似回答