我正在尝试通过存储过程从oracle 12c发送电子邮件,但是在编译时出现一些错误。
create or replace PROCEDURE email_alert as
l_mail_host VARCHAR2(50) := 'smtp.companyname.com';
l_from VARCHAR2(50) := 'email';
l_to VARCHAR2(50) := 'email';
BEGIN
UTL_MAIL.send(sender => l_from,
recipients => l_to,
subject => 'AUTOMATED_EMAIL_ALERT_10G (MYSID): Success',
message => 'AUTOMATED_EMAIL_ALERT_10G (MYSID) completed
successfully!');
EXCEPTION
WHEN OTHERS THEN
UTL_MAIL.send(sender => l_from,
recipients => l_to,
subject => 'AUTOMATED_EMAIL_ALERT_10G (MYSID): Error',
message => 'AUTOMATED_EMAIL_ALERT_10G (MYSID) failed with the
following error:' || SQLERRM);
END email_alert;
当我执行上述过程时,它会给出错误
: PLS-00201: identifier 'UTL_MAIL.SEND' must be declared. what am i missing here?
答案 0 :(得分:3)
您已经在数据库中安装了UTL_MAIL软件包。请遵循以下步骤。希望对您有帮助。
rdbms > admin
。例如C:\ProgramFiles\OracleXE\app\oracle\product\11.2.0\server\rdbms\admin
@utlmail.sql
和@prvtmail.plb
软件包GRANT EXECUTE ON UTL_MAIL TO <DB_USER>;
如果未按如下所示创建主机,则确保为主机创建了ACL(12c或更高版本的ACL创建代码),然后重试该过程。在下面的代码块中提供host和principal_name。需要。邮件服务器的默认端口为25。
begin
dbms_network_acl_admin.append_host_ace(
host=>'<example.com>',
lower_port=>25, --port if required or NULL
upper_port=>25, --port if required or NULL
ace=>xs$ace_type(privilege_list =>xs$name_list('connect','resolve'),
principal_name=>'<DB_USER>',
principal_type =>xs_acl.ptype_db));
END;