Thursday, October 2, 2014

Generate HTML/Excel Reports from SQL*Plus

HTML

1. Generate HTML/Excel page for each spooled file

SQL> set feed off markup html on spool on;
2. Create spool file
SQL> spool <file_name.html>;
3. Execute Query that need to export
SQL> select * from <your_table>;
4. Close the created spooled file
SQL> spool off;
5. Close HTML/Excel Page
SQL> set markup html off spool off;

Excel

1. Create spool file
SQL> spool <file_name.xls>;
2. Make following setting
SQL> set colsep,     --separate columns with a comma
SQL> set headsep off --separator character for the header row
SQL> set pagesize 0  --No header rows
SQL> set trimspool on --remove trailing blanks
3. Execute sql script
SQL> select * from <your_table>;
4. Close the created spooled file
SQL> spool off;

No comments:

Post a Comment