我看到这篇文章MySQL load data: This command is not supported in the prepared statement protocol yet并没有把它弄得很正确,所以我发布了自己的代码。
我有从200601开始的月度表,我需要将固定宽度的文本文件导入其中(这些也是每月一次,即200601.txt; 200602.txt; ...; 201710.txt)。
BEGIN
DECLARE count INT Default 200600;
simple_loop: LOOP
SET @a := count + 1;
SET @statement = CONCAT('
LOAD DATA LOCAL INFILE
','"D:/path/2006/',@a,'.txt"','
INTO TABLE
database.',@a,'
(@ROW)
SET proc = trim(substr(@row,1,6)),
product = trim(substr(@row,7,4)),
subp = trim(substr(@row,11,4)),
cont = trim(substr(@row,15,20)),
client = trim(substr(@row,35,8)),
sis = trim(substr(@row,43,3)),
#[and a lot more]
');
PREPARE stmt FROM @statement;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
SET count = count + 1;
IF count=200612 THEN
LEAVE simple_loop;
END IF;
END LOOP simple_loop;
END
然后我得到
Error Code: 1295. This command is not supported in the prepared statement protocol yet.
在
行 LOAD DATA LOCAL INFILE
有什么方法吗?一个软件可能吗?