oracle query output in excel file

season0891發表於2011-10-21
Code:
SQL> spool emp.xls
SQL> select empno||chr(9)||ename||chr(9)||job||chr(9)||mgr from emp;
SQL> spool off

Code:
SET MARKUP HTML ON ENTMAP ON SPOOL ON PREFORMAT OFF ;
SPOOL MY_TEST_FILE.xls;
SELECT * FROM EMP;
SPOOL OFF;

Code:
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:


Code:
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>


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/90618/viewspace-709490/,如需轉載,請註明出處,否則將追究法律責任。

相關文章