SET @idx = 1; SET @len = LENGTH(temp_accintervals) - LENGTH(REPLACE(temp_accintervals, ',', '')) + 1; WHILE @idx <= @len DO SET accinterval1 = TRIM(SUBSTRING_INDEX(SUBSTRING_INDEX(temp_accintervals, ',', @idx), ',', -1)); SELECT accinterval1; SELECT count(1) INTO records FROM t_ams_recordother t WHERE t.archivesym = accinterval1 AND FONDSCODE = '2110000' AND bookid = 0 and classno in ('银行余额调节表','银行对账单'); SELECT records; IF records = 0 THEN SELECT concat(accinterval1,' - 未查询到需要组卷的数据'); SET @idx = @idx + 1; CONTINUE WHILE; END IF; SET @idx = @idx + 1; END WHILE; 为什么报错continue
时间: 2024-01-04 21:04:47 浏览: 85
在 MySQL 中,`CONTINUE` 是一个用于循环语句的关键字,它可以跳过当前循环的剩余部分,继续执行下一次循环。但是,在上面的存储过程代码中,`CONTINUE` 后面带有 `WHILE` 关键字,这是不正确的语法,会导致语法错误。
正确的语法应该是 `CONTINUE WHILE` 或者 `CONTINUE LOOP`,其中 `WHILE` 和 `LOOP` 都是循环关键字,用于指定要继续执行的是哪个循环。因此,正确的代码应该是:
```
SET @idx = 1;
SET @len = LENGTH(temp_accintervals) - LENGTH(REPLACE(temp_accintervals, ',', '')) + 1;
WHILE @idx <= @len DO
SET accinterval1 = TRIM(SUBSTRING_INDEX(SUBSTRING_INDEX(temp_accintervals, ',', @idx), ',', -1));
SELECT accinterval1;
SELECT count(1) INTO records FROM t_ams_recordother t WHERE t.archivesym = accinterval1 AND FONDSCODE = '2110000' AND bookid = 0 and classno in ('银行余额调节表','银行对账单');
SELECT records;
IF records = 0 THEN
SELECT concat(accinterval1,' - 未查询到需要组卷的数据');
SET @idx = @idx + 1;
CONTINUE WHILE;
END IF;
SET @idx = @idx + 1;
END WHILE;
```
在正确的代码中,`CONTINUE` 后面跟着 `WHILE`,指定要跳过的是外部的 WHILE 循环。
阅读全文