我正在编写我的第一个程序并且出现错误。我已将错误减少到删除行,但不确定原因。有人可以在这里发现问题吗?是变量吗?
DROP PROCEDURE IF EXISTS MPT_PROC;
DELIMITER $$
CREATE PROCEDURE MPT_PROC
MODIFIES SQL DATA
BEGIN
#-- DECLARE statements
DECLARE v_user_id INT DEFAULT 0;
DECLARE no_more_rows BOOLEAN;
DECLARE v_loop_cntr INT DEFAULT 0;
DECLARE v_num_rows INT DEFAULT 0;
DECLARE c_userfiles CURSOR
FOR
SELECT distinct f.user_id
FROM MPT_STG_FILEUPLOAD f
WHERE f.status = 'A'; #-- Accepted
DECLARE CONTINUE HANDLER FOR NOT FOUND
SET no_more_rows = TRUE;
OPEN c_userfiles;
#-- Loop through each user_id found as pending
the_loop: LOOP
FETCH c_userfiles INTO v_user_id;
#-- Break out of the loop if
#-- 1) there were no records, or
#-- 2) we've processed them all.
IF no_more_rows THEN
CLOSE c_userfiles;
LEAVE the_loop;
END IF;
DELETE FROM MPT_STG_FILEUPLOAD s
WHERE s.user_id = v_user_id;
COMMIT; #--Commiting the changes for this user
END LOOP the_loop;
END IF;
END
DELIMITER ;