首先准备两张数据表:
一张是源数据表:aa_test
一张是备份数据表:aa_test_to
表的来源:链接:https://pan.baidu.com/s/1-tZEAYkGgxjdmrocaVvwOA 密码:3246
存储过程的代码:
BEGIN DECLARE uid varchar(100); DECLARE u_time varchar(10); DECLARE u_show VARCHAR(100); DECLARE U_NAME VARCHAR(100); DECLARE cur CURSOR FOR select id,static_time,show_dimension,type_name from aa_test; DECLARE CONTINUE HANDLER FOR NOT FOUND SET @no_record=1; open cur; loop_lable:LOOP FETCH cur into uid,u_time,u_show,u_name; IF @no_record = 1 THEN LEAVE loop_lable; END IF; INSERT INTO aa_test_to (id,static_time,show_dimension,type_name) VALUES(uid,u_time,u_show,u_name); END LOOP; close cur; END
然后执行它,就可以成功备份了。