資料庫 表 發生變化,需要把2.0的表數據 同步到3.0庫中去; -- 同步數據存儲過程執行 -- 更新留言舊表數據到新表數據中 /*DEFINER:Vector*/ drop procedure if exists p_for_feedback_message; create procedure ...
資料庫 表 發生變化,需要把2.0的表數據 同步到3.0庫中去;
-- 同步數據存儲過程執行
-- 更新留言舊表數據到新表數據中
/*DEFINER:Vector*/
drop procedure if exists p_for_feedback_message;
create procedure p_for_feedback_message()
begin
DECLARE v_done INT DEFAULT 0;
DECLARE v_id INT DEFAULT 0;
DECLARE v_feedback VARCHAR(50);
DECLARE v_user_phone VARCHAR(50);
DECLARE v_system_time VARCHAR(50);
DECLARE v_status VARCHAR(50);
DECLARE v_requDatas CURSOR FOR (SELECT f.id as id,f.feedback as feedback,f.user_phone as user_phone,f.system_time as system_time,f.`status` as status FROM feedback_message as f ORDER BY system_time DESC);
/*游標異常後捕捉並設置變數,done 為 1 跳出迴圈*/
DECLARE CONTINUE HANDLER FOR NOT FOUND SET v_done = 1;
START TRANSACTION;
/*打開游標*/
OPEN v_requDatas;
out_loop:
LOOP
/*游標向下走一步,將查詢出來的值付給定義的變數*/
FETCH v_requDatas into v_id,v_feedback,v_user_phone,v_system_time,v_status;
IF v_done = 1 THEN
LEAVE out_loop;
END IF;
BEGIN
DECLARE v_user_id VARCHAR(50);
SELECT user_id into v_user_id FROM user_info WHERE user_phone = v_user_phone LIMIT 0,1 ;
INSERT INTO feedback_message2 (id,user_id,feedback,system_time,`status`)VALUES(v_id,v_user_id,v_feedback,v_system_time,v_status);
if(v_user_phone is not null) then
select v_user_phone,v_user_id;
end if;
END;
SET v_done = 0;
END LOOP out_loop;
/*關閉游標*/
CLOSE v_requDatas;
/*事務提交*/
COMMIT;
END;