问题
For example , is it ok to do below ?
DECLARE aId VARCHAR(20);
DECLARE cur1 CURSOR FOR SELECT id FROM new_records WHERE is_loaded = false;
read_loop: LOOP
FETCH cur1 INTO aId;
...
update new_records set is_loaded = True where id = aId ;
...
CLOSE cur1;
END
回答1:
Cursors in MySQL are ASENSITIVE (13.6.6 Cursors).
An INSENSITIVE Cursor is a Cursor that effectively causes a separate copy of its result Table to be created; the Cursor accesses that copy, rather than the original result, so any changes made to the original result by other methods won't be visible to this Cursor. A SENSITIVE Cursor is a Cursor that works directly on its result Table: it makes no copy, so other changes made to the result Table will be visible to this Cursor. An ASENSITIVE Cursor may or may not make a copy of its result Table; whether other changes to its result Table will be visible is implementation-defined. The default is an ASENSITIVE Cursor.
- From DECLARE CURSOR Statement -
SQL Fiddle demo
However, depending on what you need to do, there are other ways to update the table.
来源:https://stackoverflow.com/questions/30365427/is-it-legal-to-update-cursors-querying-table-in-the-loop-of-fetching-data-from