【问题标题】:Query running fine in SQLPlus but will not run in Toad when connected to the same database查询在 SQLPlus 中运行良好,但在连接到同一数据库时不会在 Toad 中运行
【发布时间】:2014-09-24 19:59:08
【问题描述】:

我是 Toad、SQLPlus 和 Oracle 的新手。我正在尝试使用 UTL_SMTP 包运行以下查询。

DECLARE
   v_From       VARCHAR2(80) := 'noreply@myemail.com';
   v_Recipient  VARCHAR2(80) := 'MyEmail@myemail.com';
   v_Subject    VARCHAR2(80) := 'Test with attachment';
   v_Mail_Host  VARCHAR2(30) := 'smtpserver.mycompany.com';
   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 ||

    'MIME-Version: 1.0'|| crlf ||    -- Use MIME mail standard
    'Content-Type: multipart/mixed;'|| crlf ||
    ' boundary="-----SECBOUND"'|| crlf ||
    crlf ||

    '-------SECBOUND'|| crlf ||
    'Content-Type: text/plain;'|| crlf ||
    'Content-Transfer_Encoding: 7bit'|| crlf ||
    crlf ||
    'some message text'|| crlf ||    -- Message body
    'more message text'|| crlf ||
    crlf ||

    '-------SECBOUND'|| crlf ||
    'Content-Type: text/plain;'|| crlf ||
    ' name="excel.csv"'|| crlf ||
    'Content-Transfer_Encoding: 8bit'|| crlf ||
    'Content-Disposition: attachment;'|| crlf ||
    ' filename="TextFile.txt"'|| crlf ||
    crlf ||
    'Hello World'|| crlf ||    -- Content of attachment
    crlf ||

    '-------SECBOUND--'            -- End MIME mail
  );

  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: '||sqlerrm);
END;
/

如果我在 SQL Plus 中运行包(连接 / 作为 SYSDBA),它运行良好,我会收到带有附件的电子邮件。

如果我在 Toad(以 SYSTEM 连接)中运行包,我会收到以下错误消息。

[Error] ORA-06550: line 6, column 17:
PLS-00201: identifier 'UTL_SMTP' must be declared
ORA-06550: line 6, column 17:

我在本地 Oracle Database 11g Express Edition 版本 11.2.0.2.0 64 位上运行

【问题讨论】:

  • 请也格式化您的错误消息,并尝试使用与之前相同的用户
  • 您的意思是尝试使用 SYSDBA 连接到 Toad?还是以 SYSTEM 身份连接到 SQLPlus?

标签: oracle plsql oracle11g sqlplus toad


【解决方案1】:

包裹有什么特权?这些是默认 12c 安装的权限:

select grantee, privilege from dba_tab_privs where table_name = 'UTL_SMTP';

GRANTEE      PRIVILEGE
-------      ---------
PUBLIC       EXECUTE
APEX_040200  EXECUTE

如果该 PUBLIC 授权被撤销,那么即使是 SYSTEM 也无法使用该包。您可以通过以 SYS 身份登录并执行 grant execute on sys.utl_smtp to public; 来解决此问题。如果授权被撤销,您可能想找出原因。一些组织可能有禁止使用该软件包的政策,或者可能要求将其授予特定用户。

另外,请考虑使用更新、更简单的包UTL_MAIL

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-03-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-17
    • 1970-01-01
    相关资源
    最近更新 更多