Attractive Reports from SQLPLUS


Hi Everyone,

On last Friday, I finished working on automating the generation and mailing of a report. Got to learn few interesting way of generating reports directly from SQLPLUS without any extra effort and would like to share that with you.
SPOOL ON/OFF is a common functionality in SQLPLUS to write the output of query into a file. Following lines will send the output to C:\test.txt file.
SQL> SPOOL C:\test.txt
SQL> select * from employee; ---- assuming that employee is an existing table.
SQL> SPOOL OFF
Now, we might be interested in creating output report in excel format. Simplest way will be:
SQL> SET COLSEP ‘,’
SQL> SPOOL C:\test.csv    --- filename with “.csv” as extension
SQL> select * from employee; ---- assuming that employee is an existing table.
SQL> SPOOL OFF
Open test.csv in excel and you are there.
But, what if we need output in HTML format????? ………………Well, there is a way to do this as well in SQLPLUS. See below:
SQL > SET MARKUP HTML ON SPOOL ON
SQL &gt    SPOOL C:\test.html
SQL &gt    select * from employee; ---- assuming that employee is an existing table.
SQL &gt    SPOOL OFF
SQL &gt    SET MARKUP HTML OFF
SQL > EXIT
Above command “SET MARKUP HTML ON” create the result in html format. And you get the output with pre-formatted output (without any effort), see the snapshot below:

Amazingly, if we change the extension of filename from “html” to “xls” in above commands, the pre-formatted excel report is generated. The file contains the same content and looks brilliant in excel (see snapshot below) J


[This was posted on my official site on 11/1/2010 1:09 AM]

Comments

Popular posts from this blog

Sequence.nextval can really deceive you !!

Traps in Decision Making