Dear DBA-Mates, How
to get sql query output in xml format.
Hope you all are doing well and
Safe at Home!!!
We would like to share one of very important and useful
query for How to get SQL Query output in xml/xls
readable format.
This is very headache if you are running in Putty
Session.
Even we also use this same format for such queries. So,
we thought to share to you all and it will be easy for us also for references
in future.
This type of request will be send by the developer or
functional team which they may need for some analysis or monthly reports
generation.
Whatever if they asked then as a DBA we need to provide
them, even though angry inside Hahahah.
And the worst things those queries will be running 2 to 3
hrs and rows may be 2 to 3 lakhs, so can imagine it.
$sqlplus / as sysdba
SQL> SET LINESIZE 10000
SQL> SET VERIFY OFF
SQL> SET FEEDBACK OFF
SQL> SET PAGESIZE 999
SQL> SET MARKUP HTML ON ENTMAP ON SPOOL ON
PREFORMAT OFF
SQL> SPOOL <Output_Filename>.xls
SQL> set time on ## To Capture query start and end time
SQL> @<Filename>.sql
SQL> spool off;
Optional:
SQL>SET MARKUP HTML OFF ENTMAP OFF SPOOL OFF PREFORMAT
ON
SQL>SET LINESIZE 2000 VERIFY ON FEEDBACK ON
OR
SQL> set feed off markup
html on spool on
SQL> SET PAGESIZE 50000
SQL> SPOOL <output_filename>.xls
SQL> <your_query like
select * from dual;>
SQL> SPOOL OFF;
OR
SQL> set pagesize 50000
SQL> set heading on
SQL> set echo off
SQL> set colsep ','
SQL> set heading on
SQL> SET LINESIZE 999 VERIFY OFF FEEDBACK
OFF
SQL> SET MARKUP HTML ON ENTMAP ON SPOOL ON
PREFORMAT OFF
SQL> spool workflow.xls
SQL> <Your query>
SQL> Spool off;
OR
Save Query output as HTML file from SQLPLUS
As alternative you may use below block of code from the
sqlplus only to save the output as HTML file.
SQL> set linesize 4000
SQL> set verify off
SQL> set feedback off
SQL> set pagesize 9999
SQL> set markup html on entmap on spool on preformat
off
SQL> spool /tmp/query_output.html
SQL> --Your query--
SQL> set markup html off
SQL> spool off;
Hope this ma useful and helpful for everyone here.
Some more useful link:
Regards,
Pass your Oracle 1z0-517 exam with the help of Exams4usre. Exams4sure is the best place to get the authentic and approved questions answers by Experts.
ReplyDeleteYou can easily pass the exam with good marks. Get your 1z0-517 Dumps today from Exams4sure. For more information please visit us at:
<1z0-157 Online Exam
Great job
ReplyDeleteUsually I never comment on blogs but your article is so convincing that I never stop myself to say something about it. You’re doing a great job Man learn Oracle SOA Online Training
ReplyDeletesuch a nice blog and so much informational I got through your blog, thanks for sharing!!!
ReplyDeleteOracle Database Certifications