平时不怎么写存储过程,基本要用到的时候就到网上搜索,刚刚完成一个存储过程
大致作用是两个数据库,都有结构差不多的表,现在需要将一个库里该表同步到另一个库中,建了一个存储过程,并准备后面让这个存储过程自动2小时执行(这个用事件)
begin
declare b int;
declare id1, user_name1, name1, password1, salt1 VARCHAR(100);
DECLARE userType int;
declare count, grade1 int;
DECLARE count1 int;
declare cur_1 cursor for
select id, username, `name`, `password`, salt, user_type from sys_user where `status`=1 and (user_type=4 or user_type=5);
SET b = 0;
select count(1) INTO count from sys_user where `status`=1;
#select count;
OPEN cur_1;
loop_label: loop
FETCH cur_1 INTO id1, user_name1, name1, password1, salt1, userType;
select count(1) into count1 from test1.sys_user where username=user_name1;
#select count1;
if count1 = 0