MySQL 5.0 存储过程例子(使用了游标)

BEGIN

  /**给所有人默认“个人”角色*/
  DECLARE done INT DEFAULT 0;
  DECLARE a VARCHAR(32);
  DECLARE cur1 CURSOR FOR select id from party where party_type='employee';
  DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done = 1;

  /**清空occ_grant,给管理员分配“管理员”角色*/
  delete from occ_grant;

  insert into occ_grant values((select replace((select uuid()),'-','')),null,null,'admin','role1','emp-role');
  /**清空occ_grant,给管理员分配“管理员”角色*/


  OPEN cur1;

  REPEAT
    FETCH cur1 INTO a;
    IF NOT done THEN
          insert into occ_grant values((select replace((select uuid()),'-','')),null,null, a,'role7','emp-role');
    END IF;
  UNTIL done END REPEAT;
  CLOSE cur1;
   /**删除给管理员分配的“个人”角色*/
  delete from occ_grant where party_id='admin' and sec_object_id='role7';
  /**删除给管理员分配的“个人”角色*/
END

你可能感兴趣的:(mysql,object,null,delete,存储,insert)