PL/SQL下SQL结果集以html形式发送邮件
在运维的过程中,有时候需要定时将SQL查询的数据结果集以html表格形式发送邮件,因此需要将SQL查询得到的结果集拼接成html代码。对于这种情形通常有二种方式来完成。一是直接使用cron job来定时轮询并借助os级别的邮件程序来完成。其查询结果集可以直接在S
在运维的过程中,有时候需要定时将SQL查询的数据html">结果集以html表格形式发送邮件,因此需要将SQL查询得到的结果集拼接成html代码。对于这种情形通常有二种方式来完成。一是直接使用cron job来定时轮询并借助os级别的邮件程序来完成。其查询结果集可以直接在SQL*Plus下通过设置html标签自动实现html表格形式。一种方式是在Oracle中使用scheduler job来定时轮询。这种方式需要我们手动拼接html代码。本文即是对第二种情形展开描述。
关于PL/SQL下如何发送邮件可参考: PL/SQL 下邮件发送程序
1、代码描述
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
--下面的代码段主要主要是用于发送数据库A部分数据同步到数据库B是出现的错误信息
--表syn_data_err_log_tbl主要是记录错误日志,也就是说只要表中出现了新的记录或者旧记录且mailed列标志为N,即表示需要发送邮件
--下面逐一描述代码段信息,该代码段可以封装到package.
PROCEDURE email_on_syn_data_err_log (err_num OUT NUMBER,
err_msg OUT VARCHAR2)
AS
v_msg_txt VARCHAR2 (32767);
v_sub VARCHAR2 (100);
v_html_header VARCHAR (4000);
v_html_content VARCHAR (32767);
v_count NUMBER;
v_log_seq NUMBER (12);
v_loop_count NUMBER := 0;
CURSOR cur_errlog --使用cursor来生成表格标题部分
IS
SELECT '
|| TO_CHAR (sd.log_seq)
|| '
|| sd.process
|| '
|| '
|| sd.rec_id
|| '
|| '
|| REPLACE (REPLACE (sd.err_msg, '', ';')
|| '
|| '
|| TO_CHAR (sd.log_time, 'yyyy-mm-dd hh24:mi:ss')
|| '
sd.log_seq
FROM syn_data_err_log_tbl sd
WHERE sd.mailed = 'N'
ORDER BY sd.log_seq;
BEGIN
err_num := common_pkg.c_suc_general;
SELECT COUNT (*)
INTO v_count -->统计当次需要发送的总记录数
FROM syn_data_err_log_tbl sd
WHERE sd.mailed = 'N';
IF v_count > 0 --> 表示有记录需要发送邮件
THEN
SELECT 'Job process failed on ' || instance_name || 'http://www.3lian.com/' || host_name
INTO v_sub -->生成邮件的subject
FROM v$instance;
v_html_header := -->定义表格的header部分信息
'
#log-table {
margin: 0;
padding: 0;
width: 90%;
border-collapse: collapse;
font: 12px "Lucida Grande", Helvetica, Sans-Serif;
border:1px solid #CCC;
}
#log-table td {
padding: 5px;
border:1px solid #CCC;
}
#log-table th {
padding: 5px;
background: black;
color: white;
text-align: left;
}
#log-table tr:nth-child(even) td {
background: #eee;
}

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Guide to Table Border in HTML. Here we discuss multiple ways for defining table-border with examples of the Table Border in HTML.

This is a guide to Nested Table in HTML. Here we discuss how to create a table within the table along with the respective examples.

Guide to HTML margin-left. Here we discuss a brief overview on HTML margin-left and its Examples along with its Code Implementation.

Guide to HTML Table Layout. Here we discuss the Values of HTML Table Layout along with the examples and outputs n detail.

Guide to Moving Text in HTML. Here we discuss an introduction, how marquee tag work with syntax and examples to implement.

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

Guide to the HTML Ordered List. Here we also discuss introduction of HTML Ordered list and types along with their example respectively

Guide to HTML onclick Button. Here we discuss their introduction, working, examples and onclick Event in various events respectively.
