定义游标时,如果不是特别需要,使用LOCAL关键显式的将游标定义为局部游标, 尽量避免使用全局(GLOBAL,这是数据库的默认行为)游标;没有特殊需要的话, 尽量使用FORWARD_ONLY READ_ONLY STATIC游标, --For example: DECLARE your_cursor CURSOR LOCAL STATIC FORWARD_ONLY READ_ONLY FOR SELECT … OPEN your_cursor FETCH NEXT FROM cur INTO @your_variable…. WHILE @@fetch_status = 0 BEGIN -- Put your code here to use @your_variable…. FETCH NEXT FROM cur INTO @your_variable…. END CLOSE your_cursor DEALLOCATE your_cursor
?