DECLARE FoundCount INT;
DECLARE db_Name VARCHAR(255);
SET @Project_List_val = CONCAT(Project_Number_val, '_List');
SET @db_Name='test_rs';
SET @sql1 = CONCAT('SELECT COUNT(1) INTO', @FoundCount ,'
FROM information_schema.tables
WHERE table_schema =',@db_Name,'
AND table_name =', @Project_List_val);
PREPARE stmt FROM @sql1;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
IF FoundCount = 1 THEN
SET @sql = CONCAT(' INSERT INTO test (Panel_Id)
SELECT Panel_Id
FROM ', @Project_List_val);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
END IF;
这个存储过程执行得很好。但是当试图运行它时,它显示以下错误。
1064 - 您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以在第 1 行的“NULL”附近使用正确的语法
如果指定的表 (@Project_List_val) 存在,我需要运行第二个查询。