使用 MySQL 版本:5.7.20-0ubuntu0.16.04.1
你好
我写了一个小程序:
CREATE PROCEDURE fed_insert (INOUT last_user_id varchar(30), OUT success boolean)
开始
DECLARE v_user_id varchar(30) default null;
DECLARE v_count_stock_wl int default 0;
DECLARE is_online boolean default true;
DECLARE done boolean default false;
DECLARE crsr CURSOR FOR select user_id, count(distinct sc_id) from stock_watchlist where user_id > last_user_id group by user_id order by user_id;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = true;
DECLARE EXIT HANDLER FOR SQLWARNING, SQLEXCEPTION BEGIN
select 'EXITING.' as msg;
set success = false;
END;
OPEN crsr;
fetch_loop: LOOP
IF done THEN
LEAVE fetch_loop;
END IF;
select ROW_FORMAT='Dynamic' from information_schema.tables where table_name='stock_wl_t_fed' into is_online;
IF is_online THEN
fetch crsr into v_user_id, v_count_stock_wl;
insert stock_wl_t_fed values (v_user_id, v_count_stock_wl);
set last_user_id = v_user_id;
ELSE
select 'Federated table is offline.' as msg;
do sleep(1);
END IF;
END LOOP fetch_loop;
CLOSE crsr;
set success = true;
结束$$
我的问题在于处理程序:
DECLARE EXIT HANDLER FOR SQLWARNING, SQLEXCEPTION BEGIN
select 'EXITING.' as msg;
set success = false;
END;
此处理程序未检测到某些错误代码和 sqlstates
- 1161: 读取通讯包超时
- 1296: 从 %s 得到错误 %d '%s'
- SQLSTATE 'HY000'
- SQLSTATE '08S01'
在其当前形式中,处理程序有时工作,有时不工作。
问题可能出在联合表上。虽然我一无所知。
这一直困扰着我很长一段时间。
任何帮助将不胜感激。
谢谢