Wednesday, June 4, 2008

How to save query from oracle in HTML

Here's some tricks that can help in daily work with oracle. Very often, I need to extract query result from Oracle, or to be more precise ask people to send me query results. It is quite easy to save a file, that's very true but the formatting is excruciatingly unreadable. There's a flurry of tools that can allow you to export your query, but sometimes the only things you have at end because you're connecting to production environment is a good old Sql*Plus.

Here's the trick. Connect to your DB using Sql*Plus and used the following actions:

SET markup HTML on
spool test.html
SELECT * FROM mytable;
spool off
SET markup HTML off


When you type command "SET markup HTML on", your command prompt will look "funky" don't worry it is perfectly normal. After you exit you will find a nice html file. Certainly not the best format, but much more readable than plain 80 column text.