侧边栏壁纸
博主头像
王小木人

这是很长,很好的一生

  • 累计撰写 141 篇文章
  • 累计创建 43 个标签
  • 累计收到 7 条评论

目 录CONTENT

文章目录

mysqsl 存储过程 游标遍历

王小木人
2021-05-26 / 0 评论 / 0 点赞 / 852 阅读 / 899 字

/*
将超级管理员同步到新的权限管理表中,可重复执行,已存在将不在添加
/
drop procedure if exists historysuperadmin;
create procedure historysuperadmin()
BEGIN
 DECLARE  no_more_record INT DEFAULT 0;
 declare userid VARCHAR(255);
 declare rolename VARCHAR(255);
 DECLARE rolecount INT DEFAULT 0;
 DECLARE  cur_record CURSOR FOR   select a.id,a.role_id from user a where role_id='role0'; 
 DECLARE  CONTINUE HANDLER FOR NOT FOUND  SET  no_more_record = 1;
 
 
 OPEN  cur_record; 
 FETCH  cur_record INTO userid, rolename; 
 WHILE no_more_record != 1 DO
 select count(
) into rolecount from r_user_role where role_id='superadmin' AND user_id=userid; /查询是否已存在,存在就不再添加/
 if rolecount =0 THEN
  insert into r_user_role (id,role_id,user_id) values (UUID(),"superadmin",userid);
 end if;
 FETCH  cur_record INTO userid, rolename;
 
 END WHILE;
 CLOSE  cur_record; 
END
CALL historysuperadmin();
drop procedure if exists historysuperadmin;

0

评论区