day13_spool导出
2016-03-21 21:30
85 查看
1,excelvi lipengfei.sh
#!/bin/bash
/oracle/app/oracle/product/10.2.0/db_1/bin/sqlplus -S scott/lipengfei <<EOF
set linesize 200
alter session set nls_date_format='yyyy-mm-dd'
set term off verify off feedback off pagesize 30000
set markup html on entmap ON spool on preformat off
spool /home/oracle/result.xls
select * from emp;
spool off
exit; EOF
chmod 777 lipengfei.sh
lcd d:\
get /home/oracle/result.xls
2,html
下面来简单讲讲怎么利用SQLPLUS来生成HTML报表
一:首先在SQLPLUS中设置set mark html on spool on entmap off pre off
这样设置过后,利用spool 导出为html,SQLPLUS将会自动的为我们创建HTML格式,注意:如果设置pre 为on,那么输出的不是HTML格式,默认为off,entmap 默认为on ,它会将>换成HTML中的>来显示,所以我将其设置为off
二:为了格式化输出,我们需要对输出内容格式化set echo off 这样设置之后不会在HTML报表中显示执行过的SQL语句set feedback off 这样设置过后不会在HTML报表中显示已经处理多少行set heading on 设置标题显示set termout off 关闭在屏幕上的输出,这样可以加快spool执行速度set linesize 200 设置行宽度为120set pagesize 1000 设置一页显示1000行set trimout off 去掉 每行后面多余的空格
三:利用spool 输出为 *.htmlspool c:/test.html
四:写下要执行的SQL语句
五:spool off
例如要查询表空间利用率,并将结果输出为HTML报表格式:将下面的语句保存为一个SQL脚本,然后在SQLPLUS中调用
vi lipengfei.sh
#!/bin/bash
/oracle/app/oracle/product/10.2.0/db_1/bin/sqlplus -S sys/lipengfei as sysdba <<EOF
SET MARKUP HTML ON SPOOL ON pre off entmap offSET ECHO OFFSET TERMOUT OFFSET TRIMOUT OFFset feedback offset heading onset linesize 200set pagesize 10000col tablespace_name format a15col total_space format a10col free_space format a10col used_space format a10col used_rate format 99.99
spool /home/oracle/tablespace.html
select a.tablespace_name,a.total_space_Mb||'m' total_space,b.free_space_Mb||'m'free_space,a.total_space_Mb-b.free_space_Mb||'m' used_space,(1-(b.free_space_Mb/a.total_space_Mb))*100 used_rate,a.total_blocks,b.free_blocks from (select tablespace_name,sum(bytes)/1024/1024 total_space_Mb,sum(blocks) total_blocks from dba_data_filesgroup by tablespace_name) a,(select tablespace_name, sum((bytes)/1024/1024) free_space_Mb,sum(blocks) free_blocks from dba_free_spacegroup by tablespace_name) bwhere a.tablespace_name=b.tablespace_name order by used_rate desc;
spool off
exit;
EOF
chmod 777 lipengfei.sh
lcd d:\
get /home/oracle/tablespace.html
3,txtvi lipengfei.sh
#!/bin/bash
/oracle/app/oracle/product/10.2.0/db_1/bin/sqlplus -S scott/lipengfei <<EOF
set serveroutput on;set timing on;SET HEADING OFF SET SPACE 0 SET PAGESIZE 0 SET TRIMOUT ON SET TRIMSPOOL ON SET LINESIZE 2500set feedback off;
spool /home/oracle/result.txt
select DEPTNO||','||DNAME||','||LOC from dept t;
spool off
exit;
EOF
chmod 777 lipengfei.sh
lcd d:\
get /home/oracle/result.txt
来自为知笔记(Wiz)
#!/bin/bash
/oracle/app/oracle/product/10.2.0/db_1/bin/sqlplus -S scott/lipengfei <<EOF
set linesize 200
alter session set nls_date_format='yyyy-mm-dd'
set term off verify off feedback off pagesize 30000
set markup html on entmap ON spool on preformat off
spool /home/oracle/result.xls
select * from emp;
spool off
exit; EOF
chmod 777 lipengfei.sh
lcd d:\
get /home/oracle/result.xls
2,html
下面来简单讲讲怎么利用SQLPLUS来生成HTML报表
一:首先在SQLPLUS中设置set mark html on spool on entmap off pre off
这样设置过后,利用spool 导出为html,SQLPLUS将会自动的为我们创建HTML格式,注意:如果设置pre 为on,那么输出的不是HTML格式,默认为off,entmap 默认为on ,它会将>换成HTML中的>来显示,所以我将其设置为off
二:为了格式化输出,我们需要对输出内容格式化set echo off 这样设置之后不会在HTML报表中显示执行过的SQL语句set feedback off 这样设置过后不会在HTML报表中显示已经处理多少行set heading on 设置标题显示set termout off 关闭在屏幕上的输出,这样可以加快spool执行速度set linesize 200 设置行宽度为120set pagesize 1000 设置一页显示1000行set trimout off 去掉 每行后面多余的空格
三:利用spool 输出为 *.htmlspool c:/test.html
四:写下要执行的SQL语句
五:spool off
例如要查询表空间利用率,并将结果输出为HTML报表格式:将下面的语句保存为一个SQL脚本,然后在SQLPLUS中调用
vi lipengfei.sh
#!/bin/bash
/oracle/app/oracle/product/10.2.0/db_1/bin/sqlplus -S sys/lipengfei as sysdba <<EOF
SET MARKUP HTML ON SPOOL ON pre off entmap offSET ECHO OFFSET TERMOUT OFFSET TRIMOUT OFFset feedback offset heading onset linesize 200set pagesize 10000col tablespace_name format a15col total_space format a10col free_space format a10col used_space format a10col used_rate format 99.99
spool /home/oracle/tablespace.html
select a.tablespace_name,a.total_space_Mb||'m' total_space,b.free_space_Mb||'m'free_space,a.total_space_Mb-b.free_space_Mb||'m' used_space,(1-(b.free_space_Mb/a.total_space_Mb))*100 used_rate,a.total_blocks,b.free_blocks from (select tablespace_name,sum(bytes)/1024/1024 total_space_Mb,sum(blocks) total_blocks from dba_data_filesgroup by tablespace_name) a,(select tablespace_name, sum((bytes)/1024/1024) free_space_Mb,sum(blocks) free_blocks from dba_free_spacegroup by tablespace_name) bwhere a.tablespace_name=b.tablespace_name order by used_rate desc;
spool off
exit;
EOF
chmod 777 lipengfei.sh
lcd d:\
get /home/oracle/tablespace.html
3,txtvi lipengfei.sh
#!/bin/bash
/oracle/app/oracle/product/10.2.0/db_1/bin/sqlplus -S scott/lipengfei <<EOF
set serveroutput on;set timing on;SET HEADING OFF SET SPACE 0 SET PAGESIZE 0 SET TRIMOUT ON SET TRIMSPOOL ON SET LINESIZE 2500set feedback off;
spool /home/oracle/result.txt
select DEPTNO||','||DNAME||','||LOC from dept t;
spool off
exit;
EOF
chmod 777 lipengfei.sh
lcd d:\
get /home/oracle/result.txt
来自为知笔记(Wiz)
相关文章推荐
- 程序阅读
- 2016SDAU课程练习一1012 Problem M
- hrbust 1853 哈理工oj 1853 幼稚园的数学Ⅰ【Biginteger】
- Linux内核同步机制之(三):memory barrier
- BZOJ3816矩阵变换
- NFC的第一次接触
- hdu 2896 (AC自动机)
- python学习常用到的模块
- Hbase数据库简单理解
- day13_oracle—批量清空表
- day13_oracle物化视图
- day13_oracle定时任务
- day13_普通表转换成分区表——T_MOBBIZ_LOG表清理
- day13_普通表转换成分区表——具体实现
- day13_普通表转换成分区表——oracle学习之bulk collect用法
- Node.js文件操作一
- MapReduce实战--倒排索引
- 深度学习教程
- 开发中遇到tomcat有关问题问题
- 学习笔记:二分法排序,选择排序,冒泡排序,以及递归算法.