你能告诉我我的代码有什么问题吗?我跟着MySQL loop through tables循环了一个数据库的表。但是我没有从迭代光标中得到任何东西。 SELECT @sql;
输出NULL值。谢谢!
DROP PROCEDURE IF EXISTS seedinvest.insertDatabaseRowHash;
DELIMITER $$
CREATE PROCEDURE seedinvest.insertDatabaseRowHash(_schemaName varchar(100))
BEGIN
DECLARE done INT DEFAULT FALSE;
DECLARE table_name varchar(20);
DECLARE table_cursor cursor for SELECT table_name FROM information_schema.tables
WHERE table_schema = _schemaName;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
OPEN table_cursor;
table_loop: LOOP
FETCH table_cursor INTO table_name;
IF done THEN
LEAVE table_loop;
END IF;
SET @sql = CONCAT('DESC ', _schemaName, '.', table_name);
SELECT @sql; -- It outputs Null value
PREPARE stmt FROM @sql;
EXECUTE stmt;
DROP PREPARE stmt;
END LOOP;
CLOSE table_cursor;
END$$
Error Code: 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 'NULL' at line 1