我可以在 MySQL 中的同一个查询中使用 'LINES STARTING BY' 和 'LINES TERMINATED BY' 吗?
Can I use 'LINES STARTING BY' and 'LINES TERMINATED BY' on the same query in MySQL?
我正在研究一个过程,该过程使用两个准备好的语句(@aux1
和 @aux2
)将一些数据复制到文本文件中。然后复制信息的table,得到的是所有的行都被删除了。
问题是当我使用 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(执行程序时)
Error Code: 1064. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'lines terminated by ' '' at line 1
如您所见,错误发生在 lines terminated by
附近(第 1 行)。所以现在我想知道我是否可以在 lines starting by
之后使用 lines terminated by
或者是否在每个查询中只接受其中一个语句。
怎么了?
我认为你需要替换这个:
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
关键词不能重复
我正在研究一个过程,该过程使用两个准备好的语句(@aux1
和 @aux2
)将一些数据复制到文本文件中。然后复制信息的table,得到的是所有的行都被删除了。
问题是当我使用 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(执行程序时)
Error Code: 1064. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'lines terminated by ' '' at line 1
如您所见,错误发生在 lines terminated by
附近(第 1 行)。所以现在我想知道我是否可以在 lines starting by
之后使用 lines terminated by
或者是否在每个查询中只接受其中一个语句。
怎么了?
我认为你需要替换这个:
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
关键词不能重复