我已经研究了几个小时了(如何从Workbench)在存储的proc内创建一个简单的MySQL游标,但是无论我尝试什么,我总是会收到此错误:
命令不同步;您现在不能运行此命令
这是我存储的proc:
DELIMITER //
DROP PROCEDURE IF EXISTS ApplyNewFormFieldsToExistingPolicies;
CREATE PROCEDURE ApplyNewFormFieldsToExistingPolicies(argAgencyID int)
BEGIN
DECLARE done INT DEFAULT FALSE;
DECLARE t AS INT; -- TruckerID
DECLARE a AS INT; -- AgentID
DECLARE cursor1 CURSOR FOR SELECT AgentUserID AS AgentID, ID AS TruckerID from Users where IsTrucker = 1 AND AgencyID = argAgencyID
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
OPEN cursor1;
read_loop: LOOP
FETCH cursor1 INTO t, a;
-- do something with 't'
-- do something with 'a'
END LOOP;
CLOSE cursor1;
END //
DELIMITER ;
此sql有效,并返回预期数据:
SELECT AgentUserID AS AgentID, ID AS TruckerID from Users where IsTrucker = 1 AND AgencyID = 1
有什么想法我做错了吗?