I am working on a proprietary data warehousing product that has a metadata table containing the SQL queries used to populate it. I need to extract each of these queries from the metadata table and save it to its own .sql file, named according to the table it populates.
There are about 400 of these queries, and I'd like to automate it, but I don't know a good way to do that. Is there a good way to iterate across the result set, line-by-line, and write the output to a file?
An example of what I'm trying to do. Let's say I returned two lines in my result set:
select tableName, extractQuery from packages;
tableName extractQuery
Table1 select * from sourceTable1;
Table2 select * from sourceTable2;
Then I would need this to be saved into two distinct files, Table1.sql and Table2.sql, each containing the returned SQL command.