CREATE DEFINER=`taobao`@`%` PROCEDURE `insert_data_from_txt`(IN file_name VARCHAR(255)) BEGIN DECLARE done INT DEFAULT FALSE; DECLARE line VARCHAR(255); DECLARE col1 VARCHAR(8); DECLARE col2 VARCHAR(5); DECLARE col3 VARCHAR(6); DECLARE file_cursor CURSOR FOR SELECT * FROM INFORMATION_SCHEMA.FILES WHERE FILE_NAME = file_name; DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE; OPEN file_cursor; FETCH file_cursor INTO line; WHILE NOT done DO SET col1 = TRIM(SUBSTRING(line, 1, 8)); SET col2 = TRIM(SUBSTRING(line, 9, 5)); SET col3 = TRIM(SUBSTRING(line, 14, 6)); INSERT INTO axsdc (name1, aaaa, cccc) VALUES (col1, col2, col3); FETCH file_cursor INTO line; END WHILE; CLOSE file_cursor; END 这段存储过程 运行 CALL insert_data_from_txt('abcd.txt');后报错 ERROR 1328 (HY000): Incorrect number of FETCH variables
时间: 2024-02-14 08:12:45 浏览: 165
MySQL 5.7 create VIEW or FUNCTION or PROCEDURE
这个错误是因为在 FETCH file_cursor INTO line; 这一行中,变量的数量不正确。在你的存储过程中,只有一个变量 line,但是在 FETCH 语句中,使用了多个变量。可以尝试修改为:
FETCH file_cursor INTO line;
或者修改文件中每行数据的格式,以匹配你在存储过程中定义的变量数量和类型。
阅读全文