我找不到如何将变量用作Outfile。
DECLARE wOutFile CHAR(256);
SET wOutFile = CONCAT('c/data/',wDateStr,'.csv');
SELECT * FROM sometable
INTO OUTFILE wOutFile;
以上内容在最后一行呈现错误。 MySQL Workbench中的语法分析器不喜欢最后一行的wOutFile。
有没有办法告诉解析器使用变量的内容?
我试图寻找一段时间,但我不能很好地回答我的问题。
答案 0 :(得分:3)
如果您想从字符串中创建新语句,则应使用prepared statements -
DECLARE wOutFile CHAR(256);
SET wOutFile = CONCAT('c/data/',wDateStr,'.csv');
SET @var = CONCAT('SELECT * FROM sometable INTO OUTFILE ', wOutFile);
PREPARE stmt FROM @var;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;