mysql - 嵌套游标声明问题 Mysql
问题描述
我正在尝试按照此指令在 Mysql 中创建一个嵌套游标。
然后我得到了这个问题:
#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
我有 2 个表“帐户”和“n_activity”(表“帐户”中的 n = account_id)
例如:我有表“帐户”和“20_activity”。
所以我想循环“account_id”并从该循环中获取“activity_id”。
这是我的代码:
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();
请帮忙,谢谢。
解决方案
推荐阅读
- php - Wordpress:如何使用自动换行
仅在帖子中
- python - matplotlib 中动画的正确实现
- continuous-integration - Gitlab CI/CD 只部署一个阶段
- laravel - 返回重复记录的id
- php - 我的 AES 函数正确加密值,但解密返回 FALSE
- java - 如何以 1000 行为单位读取大型 .txt 文件
- angular - Angular 8 Http Post 从订阅中获取布尔值
- sql - 在将数据插入 SQL 时,索引(从零开始)必须大于或等于零且小于 EF 核心中参数列表的大小
- javascript - 将 PHP 数组传递给 JavaScript for 循环
- reactjs - 将 Firebase 照片传输到 G-Drive