Hi All,
I have seen many examples of spooling query output in csv file.
But I want to spool the query results in proper excel file.
Can you guys help me on this?
Something like this:
SQL> spool emp.xls
SQL> select empno||chr(9)||ename||chr(9)||job||chr(9)||mgr from emp;
SQL> spool off
chr(9) is the tab character, so essentially you are creating a "tsv" (tab-separated values) file that has the extension "xls".
Thereafter you can simply double-click on it and MS Excel, or an equivalent program, should be able to do the rest.
Hope that helps,
tyler_durden
_______________________________________
"Only after disaster can we be resurrected."
Try this:
SET MARKUP HTML ON ENTMAP ON SPOOL ON PREFORMAT OFF ;
SPOOL MY_TEST_FILE.xls;
SELECT * FROM EMP;
SPOOL OFF;
regards,
Arun.
Thank you Guys.
Both your solutions worked perfectly fine.
I tried set heading on to display column names in the excel but it didn't work.
Did I missed something?
Put the following commands in a script, say, C:\test.sql
set heading off pages 0 trimspool on feedback off echo off
spool c:\emp.xls
select 'EMPNO'||chr(9)||'ENAME'||chr(9)||'JOB'||chr(9)||'MGR' from dual
union all
select empno||chr(9)||ename||chr(9)||job||chr(9)||mgr from emp;
spool off
Then, from the SQL prompt:
test@ORA10G>
test@ORA10G> host type c:\test.sql
set heading off pages 0 trimspool on feedback off echo off
spool c:\emp.xls
select 'EMPNO'||chr(9)||'ENAME'||chr(9)||'JOB'||chr(9)||'MGR' from dual
union all
select empno||chr(9)||ename||chr(9)||job||chr(9)||mgr from emp;
spool off
test@ORA10G>
test@ORA10G> @c:\test.sql
EMPNO ENAME JOB MGR
7369 SMITH CLERK 7902
7499 ALLEN SALESMAN 7698
7521 WARD SALESMAN 7698
7566 JONES MANAGER 7839
7654 MARTIN SALESMAN 7698
7698 BLAKE MANAGER 7839
7782 CLARK MANAGER 7839
7788 SCOTT ANALYST 7566
7839 KING PRESIDENT
7844 TURNER SALESMAN 7698
7876 ADAMS CLERK 7788
7900 JAMES CLERK 7698
7902 FORD ANALYST 7566
7934 MILLER CLERK 7782
test@ORA10G>
Hope that helps,
tyler_durden
______________________________________________
"Only after disaster can we be resurrected."