Usually, getting the data out of the database was fairly easy with a SQL select statement, yet, bringing the data into an excel worksheet was sort of a recurring PITA: I would start SQL Developer, execute the select statement, copy the result set (ctrl-c), open Excel, paste the result set (ctrl-v) then I'd adjust the widths of the columns, and only then I'd save the resulting excel sheet.
Not that these steps are too hard, but I always felt that should be easier. So, I have written the procedure xlsx_writer.sql_to_xlsx
. This procedure takes an SQL statement and the name of an Excel file to be written, executes the SQL statement and writes the Excel file.
In SQL*Plus, that would look like:
Of course, this can be written in one line, I have used four lines because of the width limit in this blog.