我可以在MySQL的同一查询中使用'LINES STARTING BY'和'LINES TERMINATED BY'吗?

问题描述 投票:1回答:1

我正在使用两个准备好的语句(@aux1@aux2)将一些数据复制到文本文件中的过程。然后复制信息的表,删除所有行。

问题是,当我使用call copyIntoFile()执行该过程时出现错误。

步骤

delimiter !!
drop procedure if exists copyIntoFile !!
create procedure copyIntoFile()

begin
    declare path varchar(255);
    set path = concat("'C:/ProgramData/MySQL/MySQL Server 5.7/Uploads/", curdate(), ".txt'");

    set @aux1 = concat("select * from movie_modification where modified = true into outfile ", path, 
                        " fields terminated by ';' lines starting by 'Edit: ' lines terminated by '\n';");
    prepare stmt1 from @aux1;
    execute stmt1;
    deallocate prepare stmt1;

    set @aux2 = concat("select * from movie_modification where modified = false into outfile ", path, 
                        " fields terminated by ';' lines starting by 'New: ' lines terminated by '\n';");
    prepare stmt2 from @aux2;
    execute stmt2;
    deallocate prepare stmt2;

    delete from movie_modification;
end !!
delimiter ;

ERROR(执行过程时)

错误代码:1064。您的SQL语法有错误;检查与您的MySQL服务器版本相对应的手册以获取正确的语法,以在'第1行以'''终止的行附近使用]

如您所见,该错误发生在lines terminated by附近(在第1行)。因此,现在我想知道是否可以在lines terminated by之后使用lines starting by还是在每个查询中仅接受此语句之一。

怎么了?

我正在使用一个使用两个准备好的语句(@ aux1和@ aux2)将一些数据复制到文本文件中的过程。然后将信息复制到的表中,删除所有行。 ...

mysql sql select stored-procedures prepared-statement
1个回答
1
投票
© www.soinside.com 2019 - 2024. All rights reserved.