当我尝试准备时,mysql得到错误1064

时间:2017-11-13 15:43:47

标签: mysql

我试图找到lastday table并导出到另一个文件夹,代码是:

select @lastday := date_sub(curdate(),interval 1 day);
    SET @datanewname = '_m2_raw_Data';
    SELECT @datalasttablename:=concat(@lastday,@datanewname);
    set @path = ' into outfile ''C:\\Db\\test.csv''' ;
    set @field = ' FIELDS TERMINATED BY '',''' ;
    set @enclosed = ' OPTIONALLY ENCLOSED BY ''"''' ;
    set @lines = ' LINES TERMINATED BY ''\\n''';
    set @select = ' select * from';
    select @query:=concat(@select,@datalasttablename,@path,@field,@enclosed,@lines);
    select @query;
    prepare a from @query;

select @query的结果是:

 select * from2017-11-12_m2_raw_Data into outfile 'C:\Db\test.csv'
 FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' LINES TERMINATED
 BY '\n'

但错误随附

  

错误代码:1064。您的SQL语法有错误;检查   与您的MariaDB服务器版本对应的手册   第1行0.000秒<@pery'附近使用的语法

1 个答案:

答案 0 :(得分:0)

此声明无效

prepare a @query;

这就是mysql所期望的

PREPARE stmt_name FROM preparable_stmt

从我所看到的情况来看,你可能想要这样的东西:

PREPARE a FROM @query;

Read more about preparing statements here.