这是存储过程。我想要做的是遍历所有数据库并查找特定表中的行数。如果count为0,则打印表格。
DELIMITER $$
CREATE PROCEDURE checkTableData()
BEGIN
DECLARE done INT DEFAULT 0;
DECLARE db VARCHAR(255);
DECLARE appDBs CURSOR FOR SELECT schema_name FROM information_schema.schemata WHERE schema_name LIKE 'db_%';
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;
DECLARE intCount INT default;
OPEN appDBs;
REPEAT
FETCH appDBs INTO db;
IF NOT done THEN
SET @SQL = CONCAT('SELECT @intCount = COUNT(1) FROM ', db, '.SMS_CODES');
EXECUTE @SQL;
IF @intCount = 0 THEN
SELECT db;
END IF;
END IF;
UNTIL done END REPEAT;
CLOSE appDBs;
END $$
delimiter ;
错误在
行 IF NOT done THEN
编辑:
试过IF done != 0 THEN
。错误消息:
You have an error in your SQL; Check the manual that corresponds to your MySQL server version for the right syntax to use near ;
OPEN appDBs;
REPEAT
FETCH appDBs INTO db;
`IF don' at line 7
编辑: Per @Gerve我更新了proc并将intCount声明移动到光标上方的顶部,然后将其设置为0.这样错误就消失了。现在又出现了另一个错误:
You have an error in your SQL; Check the manual that corresponds to your MySQL server version for the right syntax to use near '@SQL
@SQL = CONCAT('SELECT @intCount = COUNT(1) FROM ', db, '.ECR_SMS_COUNTRY_CODES');
EXECUTE @SQL;
END IF;
UNTIL done END REPEAT;
CLOSE appDBs;
EN' at line 15