使用SQL*PLUS构建完美excel或html输出
转自:http://hong9270503.blog.163.com/blog/static/127292320091611319516/
通过SQL*PLUS我们可以构建友好的输出,满足多样化用户需求。
本例通过简单示例,介绍通过sql*plus输出xls,html两种格式文件.
首先创建两个脚本:
1.main.sql
用以设置环境,调用具体功能脚本
2.功能脚本-get_tables.sql
为实现具体功能之脚本
通过这样两个脚本可以避免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文件,通过下图我
们可以看到输出效果:
把main.sql脚本中的,spool tables.xls更改为spool
tables.htm,我们可以获得htm格式输出,效果如下图:
相关文档:
http://www.experts-exchange.com/Programming/Languages/C/Q_24038236.html
/* CWebPage.c
This is a Win32 C application (ie, no MFC, WTL, nor even any C++ -- just plain C) that demonstrates
how to embed a browser "control" (actually, an OLE object) in your own window (in order to display a
web p ......
在SQL Server2005中有FOR XML 用法,可以讲一个表作为一个字段。
我的设计想法主要是用在1对多的关系中表读取的问题。
表A 表B
在A中有一条记录而在B中有多条记录可以参照下面的写法:(我的项目中用到的,修改了字段主要是演示用)
select A.*,
(SELECT a, CAST(G_Univalence AS NVARCHAR(48)) AS G_Univa ......
/*------------------------------------------------------------------
-- Author : htl258(Tony)
-- Date : 2010-04-16 14:30:23
-- Version: Microsoft SQL Server 2008 (RTM) - 10.0.1600.22 (Intel X86)
Jul 9 2008 14:43:34
&nb ......
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_convert]') and xtype in (N'FN', N'IF', N'TF'))&n ......
如图1、2,id=1的数据是NULL,其他的为非NULL的数据。
一般情况下,会用两种方法!
方法1.t-sql:insert into E values(1,'NULL'),插入后,在打开表的情况下看到的
是'NULL'(我想是为了区分NULL,才加的引号),但是查询的时候不影响,显示的是NULL,
如图1、2,id为6的数据。
如果要插入带单引号的'NULL',insert i ......