admin管理员组文章数量:1279248
I have a comma-separated list of file names, and I want to create multiple text files in MySQL. Each file should contain some static text.
For example, if my input is:
'file1,file2,file3,file4'
I want to generate:
/var/www/output/file1.txt
containing"SomeContent"
/var/www/output/file2.txt
containing"SomeContent"
/var/www/output/file3.txt
containing"SomeContent"
/var/www/output/file4.txt
containing"SomeContent"
I want to achieve this without using loops.
I tried using SELECT INTO OUTFILE
like this:
SELECT "SomeContent" INTO OUTFILE "/var/www/output/file1.txt";
SELECT "SomeContent" INTO OUTFILE "/var/www/output/file2.txt";
SELECT "SomeContent" INTO OUTFILE "/var/www/output/file3.txt";
SELECT "SomeContent" INTO OUTFILE "/var/www/output/file4.txt";
This works, but I have 50+ file names, so manually writing queries for each file is not practical.
I also tried inserting the values into a temporary table and running:
SELECT "SomeContent", CONCAT('/var/www/output/', name, '.txt') AS filepath
FROM file_names
INTO OUTFILE "/var/www/output/dummy.txt";
But MySQL does not support dynamic filenames in INTO OUTFILE
, so it only writes to dummy.txt
instead of creating multiple files.
- Is there a way in MySQL to create multiple files dynamically from a comma-separated list without using loops?
- If not, is there any SQL-only workaround to achieve this?
本文标签:
版权声明:本文标题:sql - How to create multiple files with different names and content using a comma-separated list without loops? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741253668a2366262.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论