Py学习  »  DATABASE

在MySQL中,我可以在同一个查询上使用“以开始的行”和“以结束的行”吗?

user157629 • 5 年前 • 1387 次点击  

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

问题是当我使用 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 ;

(执行过程时)

错误代码:1064。您的SQL语法有错误;请查看与MySQL服务器版本相对应的手册,在第1行的“以“”结尾的行”附近使用正确的语法

如您所见,错误发生在 lines terminated by (在第1行)。所以现在我想知道我能不能用 行终止于 之后 lines starting by

发生了什么?

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/57312
 
1387 次点击  
文章 [ 1 ]  |  最新文章 5 年前
GMB
Reply   •   1 楼
GMB    5 年前

我认为你需要替换这个:

select ...
into outfile ...
fields terminated by ';' lines starting by 'Edit: ' lines terminated by '\n'

使用:

select ...
into outfile ...
fields terminated by ';' lines starting by 'Edit: ' terminated by '\n'

lines 关键字不应重复。