Py学习  »  DATABASE

嵌套游标声明问题Mysql

fudu • 4 年前 • 352 次点击  

我试图在Mysql中创建一个嵌套的游标,方法是 instruction .

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'DECLARE activityids CURSOR FOR SELECT activity_id FROM @_activity;
END BLOCK2;' at line 22

我有两个表'account'和'n_activity'(n=表'account'中的account_id)
例句:我有“账户”和“20”活动表。


enter image description here enter image description here

这是我的代码:

DROP PROCEDURE if exists update_schema_activity_startdate_and_duedate;
DELIMITER $$
CREATE PROCEDURE update_schema_activity_startdate_and_duedate()
BEGIN

  DECLARE done INT DEFAULT FALSE;
  DECLARE accountid INT;  
  --
  -- GET ALL ACCOUNT ID
  --

  DECLARE accountids CURSOR FOR SELECT account_id FROM account;

  --
  -- LOOP 
  --  

  OPEN accountids; 
  read_loop: LOOP 
    FETCH accountids INTO accountid;

    BLOCK2: BEGIN
        SET @_activity = CONCAT(accountid,'_activity');
        DECLARE activityids CURSOR FOR SELECT activity_id FROM @_activity;
    END BLOCK2;

  END LOOP; 
  CLOSE accountids;
END$$
DELIMITER ;
CALL update_schema_activity_startdate_and_duedate();

请帮忙,谢谢。

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/55260
 
352 次点击