MySQL简单存储过程修复用户表

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
文章目录