游标的使用
要声明,
1.接收游标数据的变量
2.遍历数据结束标志
3.游标数据来源--游标
4.将结束标志绑定到游标
然后才是打开游标
根据标志来操作游标
关游标
CREATE PROCEDURE DEL_SUB1() READS SQL DATA BEGIN DECLARE sub_id INT; DECLARE done INT DEFAULT 0; DECLARE cur1 CURSOR FOR select subscribe_id from sy_subscribe where length(source_keyword)=CHARACTER_LENGTH(source_keyword) and length(source_keyword)=32; DECLARE CONTINUE HANDLER FOR NOT FOUND SET done=1; OPEN cur1; emp_loop: LOOP FETCH cur1 INTO sub_id; select sub_id; -- 输出到控制台 if done=0 then update sy_subscribe t , sy_subscribe t1 set t.source_keyword= t1.source_id , t.source_id = t1.source_keyword ,t.unique_id = CONCAT(t1.source_id,'_',t1.source_keyword) where t.subscribe_type = 1 and t.subscribe_id = t1.subscribe_id and t.subscribe_id = sub_id; end if; IF done=1 THEN LEAVE emp_loop; END IF; END LOOP emp_loop; CLOSE cur1; END