我有以下存储过程
DELIMITER ##
CREATE PROCEDURE exportFile()
BEGIN
Select * from Sample
INTO OUTFILE '~/Sample.csv'
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\n';
END ##
DELIMITER ;
ERROR 1086 (HY000): File '~/Sample.csv' already exists
- 理所当然。 问题:我该怎么做?
答案 0 :(得分:6)
为什么不在文件中附加时间戳?
这是一个向文件追加时间戳的示例:
DELIMITER ##
CREATE PROCEDURE exportFile()
BEGIN
Select * from Sample
INTO OUTFILE CONCAT('~/Sample', CONCAT(DATE_FORMAT( your_date_field, '%d%m%Y') ,'.csv'))
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\n';
END ##
DELIMITER ;
答案 1 :(得分:3)
我达到了调试递归存储过程的类似要求。
这对我有用:
SET @s = CONCAT('SELECT * INTO OUTFILE ',"'", CONCAT('Result',FLOOR(1000+RAND()*9999)),'.txt',"'",' FROM TempTable112');
PREPARE stmt2 FROM @s;
EXECUTE stmt2;
DEALLOCATE PREPARE stmt2;
我使用xampp并在C:\ xampp \ mysql \ data \ myfolder获得输出。