1. <i id='kvXAY'><tr id='kvXAY'><dt id='kvXAY'><q id='kvXAY'><span id='kvXAY'><b id='kvXAY'><form id='kvXAY'><ins id='kvXAY'></ins><ul id='kvXAY'></ul><sub id='kvXAY'></sub></form><legend id='kvXAY'></legend><bdo id='kvXAY'><pre id='kvXAY'><center id='kvXAY'></center></pre></bdo></b><th id='kvXAY'></th></span></q></dt></tr></i><div id='kvXAY'><tfoot id='kvXAY'></tfoot><dl id='kvXAY'><fieldset id='kvXAY'></fieldset></dl></div>
  2. <tfoot id='kvXAY'></tfoot>

    <small id='kvXAY'></small><noframes id='kvXAY'>

      <legend id='kvXAY'><style id='kvXAY'><dir id='kvXAY'><q id='kvXAY'></q></dir></style></legend>
        <bdo id='kvXAY'></bdo><ul id='kvXAY'></ul>
    1. 如何将日志表中的数据导出到oracle中的电子邮件正文

      时间:2023-09-19
        <tbody id='9v50J'></tbody>

      <small id='9v50J'></small><noframes id='9v50J'>

      • <tfoot id='9v50J'></tfoot>
        • <bdo id='9v50J'></bdo><ul id='9v50J'></ul>

            1. <i id='9v50J'><tr id='9v50J'><dt id='9v50J'><q id='9v50J'><span id='9v50J'><b id='9v50J'><form id='9v50J'><ins id='9v50J'></ins><ul id='9v50J'></ul><sub id='9v50J'></sub></form><legend id='9v50J'></legend><bdo id='9v50J'><pre id='9v50J'><center id='9v50J'></center></pre></bdo></b><th id='9v50J'></th></span></q></dt></tr></i><div id='9v50J'><tfoot id='9v50J'></tfoot><dl id='9v50J'><fieldset id='9v50J'></fieldset></dl></div>
              <legend id='9v50J'><style id='9v50J'><dir id='9v50J'><q id='9v50J'></q></dir></style></legend>

              1. 本文介绍了如何将日志表中的数据导出到oracle中的电子邮件正文的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                oracle 中有没有办法将数据从表导出到电子邮件?问题是,我有一个日志表,用于保存失败的日志.我想要一个程序来检查前一天是否有任何日志,如果有,则通过电子邮件发送它们.结果应该类似于:

                is there a way in oracle how to export data from table to email? The thing is, I have a log table, where I keep failed logs. I would like to have a procedure which check if there are any logs on the day before, if yes then sends them in an email message. The result should look something like:

                Log_id - Procedure_name - Fail_type - Message
                Log_id - Procedure_name - Fail_type - Message
                Log_id - Procedure_name - Fail_type - Message
                Log_id - Procedure_name - Fail_type - Message
                

                这就是我现在的程序

                PROCEDURE send_mail(v_recipient VARCHAR2
                                     ,v_subject   VARCHAR2
                                     ,v_text      VARCHAR2
                                     ,v_from      VARCHAR2 DEFAULT 'hsdfafjh@jhh.jij') IS
                    v_mail_host VARCHAR2(30) := 'hgiugiuyg';
                    v_mail_conn utl_smtp.connection;
                    crlf        VARCHAR2(2) := chr(13) || chr(10);
                  BEGIN
                    v_mail_conn := utl_smtp.open_connection(v_mail_host, 25);
                    utl_smtp.helo(v_mail_conn, v_mail_host);
                    utl_smtp.mail(v_mail_conn, v_from);
                    utl_smtp.rcpt(v_mail_conn, v_recipient);
                    utl_smtp.data(v_mail_conn, 'Date: ' ||
                                   to_char(SYSDATE, 'Dy, DD Mon YYYY hh24:mi:ss') || crlf ||
                                   'From: ' || v_from || crlf || 'Subject: ' ||
                                   v_subject || crlf || 'To: ' || v_recipient || crlf || crlf ||
                                   v_text || crlf);
                      utl_smtp.quit(v_mail_conn);
                  EXCEPTION
                    WHEN utl_smtp.transient_error OR utl_smtp.permanent_error THEN
                      raise_application_error(-20000, 'Unable to send mail', TRUE);
                  END;
                

                推荐答案

                您可以生成 HTML 脚本并将其添加到邮件中.就像如果您想要表格格式一样,您可以创建 HTML 脚本并将其附加到邮件中.

                You can generate an HTML script and add it in mail. Like if you want a tabular format, you can create the HTML script and attach it in mail.

                以下内容供参考

                DECLARE
                   p_message_body   CLOB                := EMPTY_CLOB ();
                   p_smtp_host      VARCHAR2 (20)       := <SMTP_SERVER_IP>;
                   p_smtp_port      VARCHAR2 (10)       := '25';
                   p_message_type   VARCHAR2 (100)      := ' text/html';
                   crlf             VARCHAR2 (2)        := UTL_TCP.crlf;
                   ls_dt_start      VARCHAR2 (50);
                   ls_dt_end        VARCHAR2 (50);
                   l_mail_conn      UTL_SMTP.connection;
                   pf_to_name       VARCHAR2 (100);
                BEGIN
                   BEGIN
                      SELECT TO_CHAR (SYSDATE - 1, 'HH12:MI:SS AM'),
                             TO_CHAR (SYSDATE + 1, 'HH12:MI:SS AM')
                        INTO ls_dt_start,
                             ls_dt_end
                        FROM DUAL;
                   EXCEPTION
                      WHEN OTHERS
                      THEN
                         NULL;
                   END;
                
                   p_message_body :=
                      '<HTML> <HEAD> <STYLE> table, th, td { border: 1px solid black; border-collapse: collapse; } </STYLE> </HEAD> ';
                   p_message_body :=
                         p_message_body
                      || '<BODY> <P> <FONT COLOR="BLACK",FONT FACE ="ARIAL",FONT SIZE ="2.5"> Hello , <BR/><BR/><BR/> Dummy Message. Find Table Below ';
                   p_message_body :=
                         p_message_body
                      || '<BR/><BR/> <TABLE> <TR> <TH>Start Time</TH> <TH>End Time</TH> </TR> <TR> <TD>'
                      || ls_dt_start
                      || '</TD> <TD>'
                      || ls_dt_end
                      || '</TD> </TR> </TABLE> </BODY> </HTML>';
                   l_mail_conn := UTL_SMTP.open_connection (p_smtp_host, p_smtp_port);
                   UTL_SMTP.helo (l_mail_conn, p_smtp_host);
                   UTL_SMTP.mail (l_mail_conn, 'TEST@ORACLE.COM');
                   pf_to_name := 'abc@xyz.com';
                   UTL_SMTP.rcpt (l_mail_conn, 'abc@xyz.com');
                   UTL_SMTP.open_data (l_mail_conn);
                   UTL_SMTP.write_raw_data (l_mail_conn,
                                            UTL_RAW.cast_to_raw ('To: ' || pf_to_name || crlf)
                                           );
                   UTL_SMTP.write_raw_data
                                 (l_mail_conn,
                                  UTL_RAW.cast_to_raw (   'Date: '
                                                       || TO_CHAR
                                                                 (SYSDATE,
                                                                  'Dy, DD Mon YYYY hh24:mi:ss'
                                                                 )
                                                       || crlf
                                                      )
                                 );
                   UTL_SMTP.write_raw_data (l_mail_conn,
                                            UTL_RAW.cast_to_raw (   'From: '
                                                                 || 'TEST@ORACLE.COM'
                                                                 || crlf
                                                                )
                                           );
                   UTL_SMTP.write_raw_data (l_mail_conn,
                                            UTL_RAW.cast_to_raw (   'Subject: '
                                                                 || 'Test {'
                                                                 || TO_CHAR (SYSDATE,
                                                                             'DD Mon YYYY'
                                                                            )
                                                                 || '}'
                                                                 || crlf
                                                                )
                                           );
                   UTL_SMTP.write_raw_data (l_mail_conn,
                                            UTL_RAW.cast_to_raw ('MIME-Version: 1.0' || crlf)
                                           );
                   UTL_SMTP.write_raw_data
                      (l_mail_conn,
                       UTL_RAW.cast_to_raw
                                      (   'Content-Type: multipart/mixed; boundary="SECBOUND"'
                                       || crlf
                                       || crlf
                                      )
                      );
                   UTL_SMTP.write_raw_data (l_mail_conn,
                                            UTL_RAW.cast_to_raw ('--SECBOUND' || crlf)
                                           );
                   UTL_SMTP.write_raw_data (l_mail_conn,
                                            UTL_RAW.cast_to_raw (   'Content-Type: '
                                                                 || p_message_type
                                                                 || crlf
                                                                 || crlf
                                                                )
                                           );
                   UTL_SMTP.write_raw_data (l_mail_conn,
                                            UTL_RAW.cast_to_raw (p_message_body || crlf)
                                           );
                   UTL_SMTP.write_raw_data (l_mail_conn,
                                            UTL_RAW.cast_to_raw ('--SECBOUND' || crlf)
                                           );
                   UTL_SMTP.write_raw_data (l_mail_conn,
                                            UTL_RAW.cast_to_raw ('--SECBOUND' || crlf)
                                           );
                   --Defining content type as attachment and specifying the filename.
                   UTL_SMTP.write_raw_data (l_mail_conn, UTL_RAW.cast_to_raw ('' || crlf));
                   UTL_SMTP.write_raw_data (l_mail_conn,
                                            UTL_RAW.cast_to_raw ('--SECBOUND' || crlf)
                                           );
                   --Close connection and send mail.
                   UTL_SMTP.close_data (l_mail_conn);
                   UTL_SMTP.quit (l_mail_conn);
                EXCEPTION
                   WHEN OTHERS
                   THEN
                      NULL;
                END;
                

                你可以用你的表格替换你想要的数据.

                You can substitute the data you want with your table.

                这篇关于如何将日志表中的数据导出到oracle中的电子邮件正文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:如果(从表中选择计数(列))>0 那么 下一篇:oracle 中的 RANK() 和 DENSE_RANK() 函数有什么区别?

                相关文章

              2. <legend id='orK86'><style id='orK86'><dir id='orK86'><q id='orK86'></q></dir></style></legend>
                • <bdo id='orK86'></bdo><ul id='orK86'></ul>

                <i id='orK86'><tr id='orK86'><dt id='orK86'><q id='orK86'><span id='orK86'><b id='orK86'><form id='orK86'><ins id='orK86'></ins><ul id='orK86'></ul><sub id='orK86'></sub></form><legend id='orK86'></legend><bdo id='orK86'><pre id='orK86'><center id='orK86'></center></pre></bdo></b><th id='orK86'></th></span></q></dt></tr></i><div id='orK86'><tfoot id='orK86'></tfoot><dl id='orK86'><fieldset id='orK86'></fieldset></dl></div>

                    <small id='orK86'></small><noframes id='orK86'>

                  1. <tfoot id='orK86'></tfoot>