--- title: MySQL简单存储过程修复用户表 date: 2018-08-09 14:34:08 description: "MySQL简单存储过程修复用户表" categories: [技术总结] tags: [MySQL, 代码块] --- ```sql BEGIN DECLARE temp_id INT; DECLARE temp_accounter_id INT; DECLARE temp_accounter_no VARCHAR(64); DECLARE state VARCHAR(30); DECLARE account_book_cursor CURSOR FOR SELECT id,accounter_id FROM account_book; DECLARE CONTINUE HANDLER FOR 1329 BEGIN SET state = 'error'; END; OPEN account_book_cursor; REPEAT FETCH account_book_cursor INTO temp_id,temp_accounter_id; SELECT no INTO temp_accounter_no FROM account WHERE id = temp_accounter_id; UPDATE account_book SET accounter_no = temp_accounter_no WHERE id = temp_id; UNTIL state = 'error' END REPEAT; CLOSE account_book_cursor; END ```