1、游标循环数据写法。
2、调用存储过程写法。
CREATE DEFINER=`root`@`%` PROCEDURE `f_DispAttaOut`()
BEGIN
DECLARE done BOOLEAN DEFAULT 0;
DECLARE tmp_uid varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
DECLARE t_index CURSOR FOR select ID from lfcp_attachment where SHARE_IDS is not null and CREATED_TIME < '2020-12-01';
-- 写法一:DECLARE CONTINUE HANDLER FOR NOT FOUND SET done=1;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
-- 写法二:DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done = 1;
-- DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done = 1;
OPEN t_index;
REPEAT
FETCH t_index INTO tmp_uid;
IF done!=1 THEN
if LENGTH(tmp_uid) > 5 then
call f_DispAtta(tmp_uid); -- 调用另一个存储过程
end if;
END IF;
UNTIL done END REPEAT;
CLOSE t_index;
END