【发布时间】:2020-04-01 12:52:13
【问题描述】:
我正在学习触发器和事件,但遇到以下问题:
我创建了一个触发器,当在表 movie 中进行更新时,它会将数据插入到名为 updated_movie 的表中。
另外,我想创建一个每天上午 11:30 执行的事件,该事件创建一个文本文件,其中包含表 updated_movie 中的一些数据。到目前为止,我已经做到了:
delimiter !!
drop event if exists createFile !!
create event createFile on schedule at "11:30"
do begin
declare path varchar(255) default "/Users/Shared/BDD/L19/";
declare nameFile varchar(255) default curdate();
declare done int default 0;
declare t varchar(255);
-- creation of the text file?
declare c cursor for select title from updated_movie;
declare continue handler for not found set done = 1;
open c;
l:loop
fetch c into t;
if done = 1 then
leave l;
end if;
call copyIntoFile(t, nameFile);
end loop l;
end!!
delimiter ;
这是我每天都想执行的事件。如何在事件中声明的路径中创建一个与声明的变量nameFile具有相同文件名的文本文件?
此外,到目前为止,过程 copyIntoFile 看起来像这样:
delimiter !!
drop procedure if exists copyIntoFile !!
create procedure copyIntoFile(in str varchar(255), in fileName varchar(255)
begin
-- Copy into the text file?
end !!
delimiter ;
如何才能在文本字段中插入一些数据?
如果您想知道,updated_movie 表只有一个 varchar(255) 字段。
【问题讨论】:
-
嘿,这可能是重复的,请参阅stackoverflow.com/a/21253800/2408013 或更好的此处stackoverflow.com/a/22342839/2408013
-
这能回答你的问题吗? mysql stored procedure with INTO OUTFILE