【发布时间】:2020-07-15 11:59:22
【问题描述】:
我正在研究一个使用两个准备好的语句(@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 ;
错误(执行过程时)
错误代码:1064。您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以获取正确的语法,以便在第 1 行的“由 ''' 终止的行附近使用正确的语法
如您所见,错误发生在lines terminated by 附近(第 1 行)。所以现在我想知道是否可以在lines starting by 之后使用lines terminated by,或者在每个查询中是否只接受其中一个语句。
怎么了?
【问题讨论】:
标签: mysql sql select stored-procedures prepared-statement