初めてカーソルを作っています。
CREATE PROCEDURE `abc`.`cursordemo` (IN start_date DATETIME,IN end_date DATETIME)
BEGIN
DECLARE done INT DEFAULT FALSE;
DECLARE k1,k2,g,s,last_status VARCHAR(45);
DECLARE b, c INT;
DECLARE cur1 CURSOR FOR SELECT `key` FROM `abc`.`temp_weekly`;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
OPEN cur1;
read_loop: LOOP
FETCH cur1 INTO k1;
IF done THEN
LEAVE read_loop;
END IF;
block_cursor:BEGIN
DECLARE cur2 CURSOR FOR SELECT `key`,`group`,`status` FROM `abc`.`jira_local` WHERE `key` = k1 AND updateddate < end_date;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done1 = TRUE;
OPEN cur2;
REPEAT
FETCH cur2 INTO k2,g,s;
IF NOT done1 THEN
IF s != last_status THEN
CASE
WHEN s = 'verified' THEN
SET c = c +1;
WHEN s = 'closed' THEN
SET c = c +1;
WHEN s = 'to be scheduled' THEN
SET c = c +1;
WHEN s = 'deferred' THEN
SET c = c +1;
/*'resolved','closed','to be scheduled','deferred','validated','assigned','l3 need more info','l2 need more info','need more info'*/
WHEN s = 'resolved' THEN
SET c = c +1;
WHEN s = 'validated' THEN
SET c = c +1;
WHEN s = 'assigned' THEN
SET c = c +1;
WHEN s = 'l3 need more info' THEN
SET c = c +1;
WHEN s = 'l2 need more info' THEN
SET c = c +1;
WHEN s = 'need more info' THEN
SET c = c +1;
END CASE;
SET last_status = s;
END IF;
END IF;
UNTIL NOT done1 END REPEAT;
INSERT INTO ticketsResolvedCount values(k2,g,s,c);
END block_cursor;
END LOOP;
CLOSE cur1;
CLOSE cur2;
END$$
私がやっていること 1) temp_weekly からすべてのキーを読み取り、反復します 2) 特定のキーの jira_local テーブルからすべてのレコードを見つけ、それが検証、解決された回数などを数えます。
問題:これをコンパイルするとエラーが発生します
ERROR 1193: Unknown system variable 'done1'
また、このリンクを参照して、ループ内にストアド プロシージャを作成しました
更新:私の手順
を宣言した後done/done1
、次のようになります
BEGIN
DECLARE k1,k2,g,s,last_status VARCHAR(45);
DECLARE b, c INT;
DECLARE cur1 CURSOR FOR SELECT `key` FROM `abc`.`temp_weekly`;
DECLARE done1 BOOLEAN DEFAULT FALSE;
DECLARE done BOOLEAN DEFAULT FALSE;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
.
.
.
block_cursor:BEGIN
DECLARE cur2 CURSOR FOR SELECT `key`,`group`,`status` FROM `abc`.`jira_local` WHERE `key` = k1 AND updateddate < end_date;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done1 = TRUE;
.
.
.
これは私に与えます
ERROR 1337: Variable or condition declaration after cursor or handler declaration