定义一个Mysql存储过程
CREATE PROCEDURE sp_test () BEGIN
# 定义字符串id 类型
DECLARE id VARCHAR(36);
# 定义布尔类型 done
DECLARE done INT DEFAULT FALSE;
# 将查询结果集给examIds
DECLARE examIds CURSOR FOR select order_id from t_order;
# 将结束标志绑定到游标
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
OPEN examIds;
# 开启遍历
read_loop: LOOP
FETCH NEXT from examIds INTO id;
IF done THEN
LEAVE read_loop;
END IF;
update t_order set order_status = '1' where order_id = id;
# 结束遍历
END LOOP;
CLOSE examIds;
END;
CALL sp_test ();
drop PROCEDURE sp_test;