如何通过Automic将SQL脚本结果作为表格发送到电子邮件正文中

如何通过Automic将SQL脚本结果作为表格发送到电子邮件正文中,sql,automic,Sql,Automic,我有一个如下所示的工作流程 此工作流的第一个任务运行简单的select*查询,下一个任务发送电子邮件。他们各自工作得很好。我想要的是将SQL任务的输出作为电子邮件任务的输入发送,以便将其附加到正在发送的电子邮件中 我已经尝试在notification对象的下方字段中手动输入SQL任务的runId,它可以正常工作。但是如何使这个字段从它的前一个字段而不是硬编码字段中获取动态值呢 另外,是否有一种方法可以将select*的输出作为表格包含在电子邮件正文中 更新-1 我能够通过下面的脚本获得前面任务

我有一个如下所示的工作流程

此工作流的第一个任务运行简单的select*查询,下一个任务发送电子邮件。他们各自工作得很好。我想要的是将SQL任务的输出作为电子邮件任务的输入发送,以便将其附加到正在发送的电子邮件中

我已经尝试在notification对象的下方字段中手动输入SQL任务的runId,它可以正常工作。但是如何使这个字段从它的前一个字段而不是硬编码字段中获取动态值呢

另外,是否有一种方法可以将select*的输出作为表格包含在电子邮件正文中

更新-1

我能够通过下面的脚本获得前面任务的runId。现在只需要帮助将其包含在邮件正文中,而不是附加

:SET &NR# = SYS_ACT_PREV_NR()
:PRINT "RunID of the previous task is &NR#."
首先

设置

通过运行以下脚本加载包

sys/passwordord AS SYSDBA
@$ORACLE_HOME/rdbms/admin/utlmail.sql
@$ORACLE_HOME/rdbms/admin/prvtmail.plb
In addition the SMTP_OUT_SERVER parameter must be set to identify the SMTP server.

CONN sys/password AS SYSDBA
ALTER SYSTEM SET smtp_out_server='smtp.domain.com' SCOPE=SPFILE;
-仅在10gR1中需要重新启动实例

立即关闭

启动

我建议您在数据库服务器上使用邮件中继,而不是直接连接到外部邮件服务器。邮件中继配置可以很简单,在SMTP_OUT_SERVER参数中引用localhost。连接到外部邮件服务器的任何复杂性都将隐藏在邮件中继配置中

发送电子邮件 配置完成后,我们现在可以使用send过程发送邮件。它接受以下参数

SENDER : This should be a valid email address.
RECIPIENTS : A comma-separated list of email addresses.
CC : An optional comma-separated list of email addresses.
BCC : An optional comma-separated list of email addresses.
SUBJECT : The subject line for the email.
MESSAGE : The email body.
MIME_TYPE : Set to 'text/plain; charset=us-ascii' by default.
PRIORITY : (1-5) Set to 3 by default.
REPLYTO : Introduced in 11gR2. A valid email address.
下面是一个使用示例

BEGIN
  UTL_MAIL.send(sender     => 'me@domain.com',
                recipients => 'person1@domain.com,person2@domain.com',
                cc         => 'person3@domain.com',
                bcc        => 'myboss@domain.com',
                subject    => 'UTL_MAIL Test',
                message    => 'If you get this message it worked!');
END;
/
发送带有附件的电子邮件

该软件包还支持分别使用SEND_ATTACH_RAW和SEND_ATTACH_VARCHAR2软件包发送带有RAW和VARCHAR2附件的邮件。它们的工作方式与发送过程类似,只需几个额外的参数

SENDER : This should be a valid email address.
RECIPIENTS : A comma-separated list of email addresses.
CC : An optional comma-separated list of email addresses.
BCC : An optional comma-separated list of email addresses.
SUBJECT : The subject line for the email.
MESSAGE : The email body.
MIME_TYPE : Set to 'text/plain; charset=us-ascii' by default.
PRIORITY : (1-5) Set to 3 by default.
REPLYTO : Introduced in 11gR2. A valid email address.
附件:附件的内容。这应该是VARCHAR2或RAW,具体取决于您调用的过程

ATT_INLINE : Indicates if the attachment should be readable inline. Default FALSE.
ATT_MIME_TYPE : The default is 'text/plain; charset=us-ascii'.
ATT_FILENAME : The name for the attachment.
下面是发送带有文本附件的电子邮件的示例

BEGIN
  UTL_MAIL.send_attach_varchar2 (
    sender       => 'me@domain.com',
    recipients   => 'person1@domain.com,person2@domain.com',
    cc           => 'person3@domain.com',
    bcc          => 'myboss@domain.com',
    subject      => 'UTL_MAIL Test',
    message      => 'If you get this message it worked!',
    attachment   => 'The is the contents of the attachment.',
    att_filename => 'my_attachment.txt'    
  );
END;
/

试试看