日期:2014-05-16 浏览次数:20797 次
delimiter // CREATE PROCEDURE sp_power() begin declare l_id bigint(20); declare l_power smallint(6); declare no_more_device int default 0; declare power_csr CURSOR FOR SELECT dev_id,power_stat FROM device; DECLARE CONTINUE HANDLER FOR NOT FOUND SET no_more_device=1; SET no_more_device = 0; create table if not exists stat_power(dev_id bigint(20),dev_power smallint(6)); truncate table stat_power; open power_csr; dev_loop:repeat fetch power_csr into l_id,l_power; if no_more_device then leave dev_loop; end if; if l_power < 11 then insert into stat_power values(l_id,l_power); end if; until no_more_device end repeat dev_loop; close power_csr; set no_more_device = 0; end // delimiter ;