如何使用 concat 函数重命名文件名?我想要我的文件名和日期,谁能帮我解决这个问题。
SET @OUTFILE = CONCAT( CONCAT('/xampp/htdocs/mysite/reports-', NOW()), '.csv');
SELECT * FROM `tbl_user` INTO OUTFILE @OUTFILE FIELDS TERMINATED BY ','ENCLOSED BY '"' LINES TERMINATED BY '\n'
您可以执行以下操作:
SET @sql_text =
CONCAT (
"SELECT * FROM `tbl_user` into outfile '/xampp/htdocs/mysite/reports-"
, DATE_FORMAT( NOW(), '%Y%m%d')
, ".csv'"
);
PREPARE s1 FROM @sql_text;
EXECUTE s1;
DROP PREPARE s1;
您应该使用准备好的语句。构建一个查询字符串,然后执行它。