Basic usage of SQL Cursor

1. Cursor (execute the following equivalent to select)
2. The general format of the cursor:
declare cursor name CURSOR FOR SELECT field 1, field 2, field... FROM table name WHERE ...
OPEN cursor name
FETCH NEXT FROM cursor name INTO variable name 1, variable name 2, variable name 3,…
WHILE @@FETCH_STATUS=0
BEGIN
SQL statement execution process...
FETCH NEXT FROM cursor name INTO variable name 1, variable name 2, variable name 3,...
END
CLOSE cursor name
DEALLOCATE cursor name (delete cursor )

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325860937&siteId=291194637