LOCAL cursor
Specifies that the scope of the cursor is local to the batch, stored procedure, or trigger in which the cursor was created. The cursor name is only valid within this scope. The cursor can be referenced by local cursor variables in the batch, stored procedure, or trigger, or a stored procedure OUTPUT parameter. An OUTPUT parameter is used to pass the local cursor back to the calling batch, stored procedure, or trigger, which can assign the parameter to a cursor variable to reference the cursor after the stored procedure terminates. The cursor is implicitly deallocated when the batch, stored procedure, or trigger terminates, unless the cursor was passed back in an OUTPUT parameter. If it is passed back in an OUTPUT parameter, the cursor is deallocated when the last variable referencing it is deallocated or goes out of scope.
作用域为一个scope。cursor仅在当前scope有效。可以被当前scope内的局部cursor变量引用,也可以作为SP的输出参数。作为输出参数时,就是把该cursor返回给调用着。cursor在当前scope结束时隐式的清除,当作为SP输出参数时有点特殊,是当引用它的变量清除时清除,或者调用的scope结束时清除。(scope是指一个batch,或SP,或trigger,scope<session or connection)
GLOBAL cursor
Specifies that the scope of the cursor is global to the connection. The cursor name can be referenced in any stored procedure or batch executed by the connection. The cursor is only implicitly deallocated at disconnect.
作用域是connection。可以被当前connection内的所有scope访问。当连接结束时候清除。