창조와 MySQL의 텍스트 파일에 데이터를 추가로 문제?

AlfaCoding :

나는 두 개의 서로 다른 준비된 문을 사용하는 다음 절차를 만들었습니다, 같은 이름의 텍스트 파일에 일부 데이터를 기록합니다.

순서

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: ' 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: ' terminated by '\n';");
    prepare stmt2 from @aux2;
    execute stmt2;
    deallocate prepare stmt2;

    delete from movie_modification;
end !!
delimiter ;

나는이 절차를 실행하면, 문은 aux1제대로 실행하고 텍스트 파일을 만들고 그 안에 데이터를 기록합니다. 실행이 두 번째 문 (가는 때 aux2), 나는 다음과 같은 오류가 발생합니다 :

오류 코드 : 1086 파일 'C는 : / 경우 ProgramData / MySQL을 / MySQL 서버는 5.7 / 업로드 / 2020-04-03.txt'이 이미 존재합니다

파일이 이미 문에서 생성되고 있기 때문에이 오류가 발생합니다 aux1.

어떻게 다음 두 번째 문 수정할 수 있습니다 aux2이미 생성 된 것 파일을 알고 있습니까?

RiggsFolly :

난 당신이 같은 파일에 추가 할 MySQL을 요청할 수 있습니다 같아요,하지만 당신은 UNION에게 2 개 쿼리를 할 수 있었다.

당신은 추가 할 수 있습니다 'Edit: ''New: '쿼리에 따라서는 하나 개의 쿼리에이를 줄이기 위해 UNION을 사용할 수 있도록.

당신은 당신이 원하는 모든 열을 지정하는 쿼리를 변경해야 할 수 있습니다 SELECT 'Edit: ',*못해 일을하지만, 여기 제안입니다.

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 @aux = concat("select 'Edit: ', col1,col2 from movie_modification where modified = true
                    UNION ALL
                    select 'New: ', col1,col2 from movie_modification where modified = false
                 into outfile ", path, 
                 " fields terminated by ';' lines terminated by '\n';");

    prepare stmt from @aux;
    execute stmt;

    deallocate prepare stmt;
    delete from movie_modification;
end !!
delimiter ;

추천

출처http://10.200.1.11:23101/article/api/json?id=402155&siteId=1