0

It is quite simple to write an MySQL query result directly to a CSV file:

SELECT * FROM MyTable INTO OUTFILE '/my/file.csv'

How can I write the table output of a procedure directly to a file, i.e. something alike this?

CALL MyProc('MyPar1') INTO OUTFILE '/my/file.csv'

The procedure should not be changed.

sweber
  • 2,746
  • 2
  • 13
  • 21
  • Not tested but.... If the procedure returns a table, why can't you `SELECT CALL....` into a file (don't even know if this is permitted in MySQL, but it would be the first thing I would try). – FDavidov May 13 '18 at 12:29
  • 1
    Why don't you write the `SELECT * FROM MyTable INTO OUTFILE '/my/file.csv'` into the stored procedure and use a params to control the table name and the output path? Please remember to protect against SQL injections if you are going to use `PREPARE/EXECUTE` to allow dynamic SQL execution.. – Raymond Nijland May 13 '18 at 12:45

0 Answers0