Parametrizing SQL script

别等时光非礼了梦想. 提交于 2019-12-12 02:46:37

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!