Oracle SQL Developer has an option to export the contents of a query result to various formats (CSV/fixed width/Excel/XML). Is there any way to automate it?
If not, what free tools are available that will let me automate exports into the same formats that SQL Developer is capable of exporting to?
I don’t know of a way to automate SQL Developer exports, no.
However, it’s easy enough to generate CSV and/or fixed width files from PL/SQL (using the
UTL_FILEpackage). Tom Kyte has an example of programs that generate CSV or fixed width files using either PL/SQL or Pro*C. Either can be relatively easily automated using your favorite scheduler.XML outputs can be automated in much the same way depending on how much control you need over the XML that is actually generated. If you just need valid XML and don’t care about the format of that XML, you can do something like this using the DBMS_XMLGEN package (this example is straight from the documentation).
You could then write the
resultCLOB to a file usingUTL_FILEand, again, use your favorite scheduler to schedule it.If you just need to generate a file that Excel can open, you probably just need to create a CSV or a tab-delimited file. Excel can open either type of file relatively easily though you do get the extra step of being prompted to accept the delimiter that it found (it generally detects the delimiter correctly).
Generating native Excel output is a bit more challenging. There are PL/SQL APIs for generating Excel files such as Jason Bennett’s ExcelDoctypeUtils. But I’ve always gone with a Java stored procedure that used either the JExcelAPI or that Apache POI to generate the Excel file. This, obviously, requires a bit more work to implement. Once you have a stored procedure that can write an Excel file, as with the other options, you can automate calling that procedure using your favorite scheduler.