`
xw302
  • 浏览: 122711 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

sqlplus 生成 html report 并用sendmail发送

阅读更多
工作需要给领导做汇报,每天自动发送一份邮件,内容需要从db抓取,采用了sqlplus+sendmail(OEL5.3).

1.Sqlplus 生成HTML报表(Report.sql)
spool /home/oracle/AUTOMAIL/Report.html;//设置生成文件内容
set term on; //在终端显示运行过程
set linesize 1000; //每行的字符数,设置稍微大些,避免换行
set underline off;
set verify off;
set echo off;  //不把输出的结果显示在屏幕上
set feedback off; //回显本次sql命令处理的记录条数,缺省为on
set heading off;   //输出域标题,缺省为on
set pagesize 100; //页面行数
set trimspool on; //删除行后面的空格,如果不设置,在email中显示会有'!'
set trimout on; //删除行后面的空格
//附件是这些参数的官方文档

//html head
SELECT '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
<title>Summary Report</title></head>' FROM DUAL;


select '<center><br><b>Your query would result in' from dual;
SELECT
  count(*)
FROM tableA
WHERE 
  status >'1';
select 'records.</b><br></center>' from dual;


//css
select '<style type="text/css">' from dual;

select 'table {border-width: 1px 1px 1px 1px;border-spacing: 1px 3px 1px 3px;border-style: solid solid solidsolid;border-color: grey grey grey grey;border-collapse: collapse;}' from dual;

select 'table th {border-width: 1px 1px 1px 1px;border-style: solid solid solid solid;border-color: grey grey grey grey;font-size: 12px;-moz-border-radius: 0px 0px 0px 0px;}' from dual;

select 'table tr:hover {color: darkblue;}' from dual;

select 'table td {border-width: 1px 1px 1px 1px;padding: 1px 4px 1px 4px;border-style: solid solid solid solid;border-color: gray gray gray gray;text-align: left;font-size: 12px;-moz-border-radius: 0px 0px 0px 0px;}' from dual;

select 'table.nested {border-width: 0px 0px 0px 0px;border-spacing: 1px 3px 1px 3px;border-color: white white white white;}' from dual;

select 'table.nested tr:hover {color: darkblue;}' from dual;

select 'table.nested td {border-width: 0px 0px 0px 0px;padding: 1px 4px 1px 4px;border-color: white white white white;text-align: left;font-size: 10px;-moz-border-radius: 0px 0px 0px 0px;}' from dual;

select 'table.nolines {border-width: 0px 0px 0px 0px;border-spacing: 1px 3px 1px 3px;border-color: white white white white;}' from dual;

select 'table.nolines td {border-width: 0px 0px 0px 0px;padding: 1px 4px 1px 4px;border-color: white white white white;text-align: center;font-size: 12px;-moz-border-radius: 0px 0px 0px 0px;}' from dual;

select 'table.nolinesLeftAligned {border-width: 0px 0px 0px 0px;border-spacing: 1px 3px 1px 3px; border-color: white white white white;}' from dual;

select 'table.nolinesLeftAligned tr:hover {color: black;font-size: 14px;}' from dual;

select 'table.nolinesLeftAligned td {border-width: 0px 0px 0px 0px;padding: 1px 4px 1px 4px;   border-color: white white white white;text-align: left;font-size: 12px;font-face: Arial;-moz-border-radius: 0px 0px 0px 0px;}' from dual;

select '</style>' from dual;

//table
select '<h2 align="center"></h2>
<center>
<b>Summary Report</b>
<br>
<span id="selectedbugs">(400 records)</span>
</center>' from dual;

select '<table id="SummaryTab" class="sortable"><thead><tr style="font-family: Arial,Helvetica,Geneva,sans-serif; font-size: 10pt; font-weight: bold; text-align: center; background-color: rgb(204, 204, 153); color: rgb(51, 102, 153);">'
|| '<th>No.</th>'
|| '<th>name</th>'
|| '<th>salaries</th>'
|| '<th>department</th>'
|| '</tr></thead>' from dual;

select 
'<tr style="font-family: Arial,Helvetica,Geneva,sans-serif; font-size: 9pt;"><td>' || rownum ||'</td>',
'<td><a href=https://wwww.g.cn?no=' || '&' || 'no=' || no || '>' || rptno || '</a></td>',
'<td>' || name || '</td>',
'<td>' || salaries || '</td>',
'<td>' || department || '</td></tr>'
from 
(
select h.no,h.name ,h.salaries ,h.department
from
tableA h 
WHERE 
  h.product_id =xxxx 
  order by h.no asc, h.name desc
)
  where rownum <= 400;

spool off;




2.执行report.sql并发送邮件(automail.sh)--用crontab调用并定时发送即可
#warning,not edit or delete the content
#!bin/sh/

#script folder path
BurReportPage="/home/oracle/AUTOMAIL"

cd $BurReportPage

#connect bugDB and run sql to get date
source /home/oracle/db.env
sqlplus username/psword@servanme/sid <<EOF
@Report.sql
exit
EOF

#send mail 
cat ./Report.html|formail -I "From: mailname@x.com" -I "MIME-Version:1.0" -I "Content-type:text/html;charset=utf-8" -I "Subject:Daily Reports Automail" -I "To:abama@x.com" -I "Cc:abamb@x.com"|/usr/sbin/sendmail -oi -t


分享到:
评论

相关推荐

    使用sqlplus生成txt或者html报表

    首先,`csvreport.sql`和`htmlreport.sql`这两个文件名暗示了我们可能会使用SQLPlus执行SQL脚本来生成CSV(逗号分隔值)和HTML格式的报表。CSV是一种常见的数据交换格式,适合于导入电子表格软件如Excel进行进一步...

    sqlplus11.2 rpm安装包

    此外,SQLPlus还支持脚本执行、数据导入导出、生成报表等功能。 2. **Oracle SQLPlus 11.2**: 这个版本是指Oracle SQLPlus的11.2版,是Oracle Database 11g Release 2的一部分。11.2版带来了许多增强的功能和性能...

    SQLPLUS 手册

    8. **提示符和变量**:SQLPLUS允许定义变量并用它们在查询中,使用`ACCEPT`命令可以接收用户输入。 9. **报表生成**:通过`RUN`命令,结合外部程序(如`awk`或`sed`),可以自定义生成报表格式。 10. **系统管理**...

    java做的Sqlplus

    描述中提到这个Java版Sqlplus已经非常完善,意味着它可能具备了与原版Sqlplus相似甚至更多的功能,如查询、插入、更新和删除数据,执行脚本,管理用户权限,以及生成数据库报告等。开发者欢迎用户使用并提出反馈,这...

    SQLPLUS命令查询文档

    8. **输出重定向**:`SPOOL`命令可以把SQLPLUS的输出重定向到一个文件,这对于记录查询结果或者生成报告非常有用。 9. **游标操作**:通过`DECLARE CURSOR`, `OPEN`, `FETCH`, 和 `CLOSE`等命令,可以在SQLPLUS中...

    Sqlplus_登录数据库

    "Sqlplus 登录数据库" Sqlplus 是 Oracle 数据库管理系统中的一种命令行工具,用于与 Oracle 数据库进行交互。Sqlplus 登录数据库是指使用 Sqlplus 工具连接到 Oracle 数据库的过程。在这个过程中,用户需要输入...

    sqlplus常用命令参数

    Sqlplus 常用命令参数 Sqlplus 是 Oracle 数据库管理系统中的一种命令行工具,用于交互式地访问和管理 Oracle 数据库。下面是 Sqlplus 中的一些常用命令参数: 登录系统用户 Sqlplus 提供了多种方式来登录系统用户...

    Oracle SQLPLUS基础及sqlplus命令详解

    Oracle SQL*Plus是Oracle数据库中一个重要的命令行工具,用于执行SQL语句和PL/SQL代码,管理数据库,以及格式化输出结果。它既是Oracle开发者日常工作中不可或缺的工具,也是数据库管理员进行日常维护和故障排查时的...

    sqlplus中批量执行sql文件

    ### SQLPlus中批量执行SQL文件的方法 在日常的数据库管理工作中,经常需要对数据库进行批量操作,例如批量执行SQL脚本、更新存储过程等。在这些场景下,使用Oracle提供的命令行工具SQLPlus来批量执行SQL文件是一种...

    SQLPlus命令

    SQLPlus命令,SQLPlus命令SQLPlus命令SQLPlus命令SQLPlus命令SQLPlus命令SQLPlus命令SQLPlus命令SQLPlus命令SQLPlus命令

    SQLPlus Usage Guide

    9. **报表生成**:通过`SPOOL`命令,SQLPlus可以将查询结果输出到文件,便于生成报表或进一步分析。 10. **SQL历史记录**:`HISTORY`命令显示最近执行的SQL语句,方便复用。 11. **元数据查询**:使用`DESCRIBE`或...

    详细介绍ORACLE sqlplus命令

    详细介绍ORACLE sqlplus命令,详细介绍ORACLE sqlplus命令

    sqlplus教程(中文)

    SQLPlus是Oracle公司提供的一款强大的命令行工具,用于与Oracle数据库进行交互。它不仅支持基本的SQL查询,还可以执行复杂的数据库管理和开发任务。本教程旨在详细介绍SQLPlus的使用方法以及SQL语言在Oracle环境中的...

    sqlplus集成工具包12.zip

    SQLPlus是Oracle数据库管理系统中的一个命令行工具,用于执行SQL语句、PL/SQL块以及管理数据库。在“sqlplus集成工具包12.zip”中,我们预设这是一个包含SQLPlus基本版本及其相关实用工具的集合,适用于Oracle数据库...

    sqlplus连接数据库方法

    在IT行业中,数据库管理是至关重要的任务之一,而Oracle数据库作为全球广泛使用的数据库管理系统,其管理工具sqlplus是系统管理员和开发人员常用的交互式接口。本文将详细介绍如何使用sqlplus登录Oracle数据库,包括...

    sqlplus 批处理

    在IT领域,数据库管理是至关重要的任务,而SQLPLUS作为一个强大的命令行工具,为Oracle数据库管理员和开发人员提供了高效的操作界面。批处理是提高工作效率的重要手段,它允许用户一次性执行多个SQL语句,而非逐个...

    Oracle SQLPlus最新手册

    《Oracle SQLPlus最新手册》深度解析 一、引言 Oracle SQLPlus作为Oracle数据库系统中的一个强大工具,为用户提供了直接与数据库交互的能力。本文旨在深入解析《Oracle SQLPlus最新手册》,提炼出其中的关键知识点...

    SQLPLUS在Bash_shell的使用

    【SQLPLUS在Bash_shell的使用】 SQLPLUS是Oracle数据库管理系统提供的一款强大的SQL命令行工具,它允许用户在命令行界面执行SQL语句、PL/SQL块以及进行数据库管理任务。在Bash Shell环境下,我们可以利用Shell脚...

Global site tag (gtag.js) - Google Analytics