eygle.com   eygle.com
eygle.com  
 

« How to use Oracle BFILE | Blog首页 | 美丽的樱花 »

使用SQL*PLUS,构建完美excel或html输出

作者:eygle |【转载时请务必以超链接形式标明文章和作者信息及本声明
链接:
通过SQL*PLUS我们可以构建友好的输出,满足多样化用户需求。
本例通过简单示例,介绍通过sql*plus输出xls,html两种格式文件.
首先创建两个脚本:
1.main.sql
用以设置环境,调用具体功能脚本
2.功能脚本-get_tables.sql
为实现具体功能之脚本
通过这样两个脚本可以避免spool中的冗余信息,参考:
如何去除SQLPLUS中SPOOL的冗余信息

示例如下:
1.main.sql脚本:
[oracle@jumper utl_file]$ more main.sql
set linesize 200 
set term off verify off feedback off pagesize 999 
set markup html on entmap ON spool on preformat off
spool tables.xls
@get_tables.sql
spool off
exit

2.get_tables.sql脚本:
[oracle@jumper utl_file]$ more get_tables.sql 
select owner,table_name,tablespace_name,blocks,last_analyzed
from all_tables order by 1,2;

3.执行并获得输出:
[oracle@jumper utl_file]$ sqlplus "/ as sysdba" @main

SQL*Plus: Release 9.2.0.4.0 - Production on Mon Apr 25 10:30:11 2005

Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.


Connected to:
Oracle9i Enterprise Edition Release 9.2.0.4.0 - Production
With the Partitioning option
JServer Release 9.2.0.4.0 - Production

Disconnected from Oracle9i Enterprise Edition Release 9.2.0.4.0 - Production
With the Partitioning option
JServer Release 9.2.0.4.0 - Production
[oracle@jumper utl_file]$ ls -l tables.xls 
-rw-r--r--    1 oracle   dba         69539 Apr 25 10:30 tables.xls
[oracle@jumper utl_file]$ 

此处输出为xls文件,通过下图我们可以看到输出效果:
Excel输出
把main.sql脚本中的,spool tables.xls更改为spool tables.htm,我们可以获得htm格式输出,效果如下图:
Html输出 -----
这篇 【使用SQL*PLUS,构建完美excel或html输出】来自 www.eygle.com | CSDN技术网摘| del.icio.us|365Key

By eygle on 2005-04-25 10:55 | Comments (18) | Posted to FAQ | Edit |Pageviews:

相关文章 随机文章
  • 如何对时间进行简单加减运算
  • 并行查询并行度Degree与instances 设置
  • 关于PARALLEL_MAX_SERVERS参数的设置
  • 使用REF CURSOR处理Oracle的结果集
  • Oracle Peeking绑定变量的控制
  • 摄影习作-小小的太阳
    我的DBA飞走了
    升级MT到3.32 几个插件的选用
    回顾成都的Oracle 11g发布会
    孤独的人是可耻的
    网上相关主题:
    Google

    留言 (18)

    好方法!
    不过我有时候偷懒,使用toad也可以做到。

    Posted by: muman at April 25, 2005 2:48 PM

    妙!!!!

    html可以直接这样成为xls:-)

    妙!!!

    Posted by: jametong at April 26, 2005 4:34 AM

    在xls中显示不了中文是为什么啊?
    html是可以的

    Posted by: zhanghui at June 6, 2005 7:10 PM

    to zhanghui;

    可能是你的字符集设置问题。

    Posted by: eygle at June 7, 2005 9:00 AM

    为什么我生成的excel只有一列,而不像作者在demo中生成的excel那样,有多列

    Posted by: zy at June 14, 2005 12:58 PM

    上述spool输出只有一列的问题,是否是因为我的版本不够高,要和作者演示的excel效果一样,最低需要什么版本的客户端

    Posted by: zy at June 14, 2005 3:11 PM

    我的htm格式不太正确,如下:
    OWNER TABLE_NAME TABLESPACE_NAME BLOCKS LAST_ANALYZED ------------------------------ ------------------------------ ------------------------------ ---------- ------------- ADMIN1 CTEST1 GE_USER_DATA ADMIN1 CTEST2 GE_USER_DATA BCX HORIZON_2D USERS BCX HORIZON_2D_SEGMENT USERS BCX HORIZON_2D_SEGMENT_SET USERS BCX HORIZON_2D_SET USERS BCX HORIZON_3D USERS BCX HORIZON_3D_SET USERS BCX HORIZON_SET USERS BCX LINE_2D USERS BCX QUALITY_GENE_SEGMENT USERS BCX REF_COLOR_MAPS USERS BCX SURVEY USERS BCX WELL USERS BCX WELL_HORIZON USERS BCX WELL_HORIZON_SEGMENT USERS BCX WELL_TOP USERS CTXSYS DR$CLASS DRSYS CTXSYS DR$DELETE CTXSYS DR$INDEX DRSYS OWNER TABLE_NAME TABLESPACE_NAME BLOCKS LAST_ANALYZED ------------------------------

    Posted by: hgzuo at July 14, 2005 9:18 AM

    我的 table.xls 显示SP2-0640: 未连接

    Posted by: sunnysea2005 at July 26, 2005 12:58 PM

    未连接是你的脚本有问题,没有连到数据库

    Posted by: eygle at July 26, 2005 1:31 PM

    怎么解决这个字符集的问题呀!!???急~~

    Posted by: greendays at September 29, 2005 4:12 PM

    sqlplus must be 9.x.x.x version

    Posted by: sam at October 28, 2005 11:44 AM

    用java怎么调用?

    Posted by: zz at February 6, 2006 4:28 PM

    请教一下:为什么我用eygle的脚本,无法实现demo显示的那样的excel文件?就是无法将每一列插入到excel对应的列里。请指教。谢谢

    Posted by: Dawei at January 3, 2007 5:34 PM

    你的结果是什么样子的?

    数据库是什么版本?

    Posted by: eygle at January 3, 2007 5:44 PM

    为什么我们的格式都没有作者这么美丽!文件是可以out出来就是很难看!!!!!!!!!

    Posted by: panweiweb at April 30, 2007 11:35 AM

    不错的方法

    Posted by: 电动车 at May 29, 2007 3:03 PM

    1.使用spool导出select to_char('0123456789101010101010') from dual;的结果;
    2.导出的a.xls文件使用文本打开内容如下,0123456789101010101010,显示是正确的;
    3.但是用excel打开会有两个问题:
    A)前面的0被去掉了;
    B)变成了科学计数法显示 1.23457E+20


    body {font:10pt Arial,Helvetica,sans-serif; color:black; background:White;} p {font:10pt Arial,Helvetica,sans-serif; color:black; background:White;} table,tr,td {font:10pt Arial,Helvetica,sans-serif; color:Black; background:#f7f7e7; padding:0px 0px 0px 0px; margin:0px 0px 0px 0px;} th {font:bold 10pt Arial,Helvetica,sans-serif; color:#336699; background:#cccc99; padding:0px 0px 0px 0px;} h1 {font:16pt Arial,Helvetica,Geneva,sans-serif; color:#336699; background-color:White; border-bottom:1px solid #cccc99; margin-top:0pt; margin-bottom:0pt; padding:0px 0px 0px 0px;} h2 {font:bold 10pt Arial,Helvetica,Geneva,sans-serif; color:#336699; background-color:White; margin-top:4pt; margin-bottom:0pt;} a {font:9pt Arial,Helvetica,sans-serif; color:#663300; background:#ffffff; margin-top:0pt; margin-bottom:0pt; vertical-align:top;}SQL*Plus Report


    0123456789101010101010

    Posted by: kevin at January 21, 2008 2:16 PM

    太妙了,能否对以上代码注解一下吗?
    万分感谢!

    Posted by: cndragon at April 3, 2008 1:26 PM

    发表留言:



    Remember Me?
    (输入验证码后方可评论,谢谢支持)



    CopyRight © 2004 eygle.com, All rights reserved.