问题
I have to make
SELECT column1,column2
INTO OUTFILE 'out_1.csv'
FROM table1
WHERE column1.name = '1'
SELECT column1,column2
INTO OUTFILE 'out_2.csv'
FROM table1
WHERE column1.name = '2'
SELECT column1,column2
INTO OUTFILE 'out_3.csv'
FROM table1
WHERE column1.name = '3'
and so on... I thought it was a good idea to do something like:
SELECT column1,column2
INTO OUTFILE 'out_$1.csv'
FROM table1
WHERE column1.name = $1
and pass the parrameter $1 through a UNIX shell script. But maybe there's a better way. There is a SQL "native" way to iterate through a range from 1 to 40?
回答1:
Sure. You can create a stored procedure and use LOOP or WHILE.
来源:https://stackoverflow.com/questions/8004370/parametrizing-sql-script