我试图运行一个执行SQL的shell scrpit。在SQL文件中,我有查询来检查数据库中的某些内容,当其中一个检查失败时,它会向指定的id发送电子邮件警报。 我的代码类似于:
Declare
numrows number(4,2);
c UTL_SMTP.CONNECTION;
PROCEDURE send_header(name IN VARCHAR2, header IN VARCHAR2) AS
BEGIN
UTL_SMTP.WRITE_DATA(c, name || ': ' || header || UTL_TCP.CRLF);
END;
Begin
select count (*) into numrows
<some sub queries>
Minus
select count(*)
<from something else>
;
--if differences are found, then trigger an email.
IF numrows <> 0 THEN
BEGIN
c := UTL_SMTP.OPEN_CONNECTION('localhost',25);
UTL_SMTP.HELO(c, 'localhost');
UTL_SMTP.MAIL(c, 'a@b.com');
UTL_SMTP.RCPT(c, 'c@d.com');
UTL_SMTP.OPEN_DATA(c);
send_header('From', '"noreply" <a@b.com>');
send_header('To', '"c@d.com');
send_header('Subject', '<subject here>');
UTL_SMTP.WRITE_DATA(c,'brief error message'|| chr(13));
FOR I IN (
<some logic>
)
LOOP
UTL_SMTP.WRITE_DATA(c, xyz || ' - ');
UTL_SMTP.WRITE_DATA(c, qwe );
UTL_SMTP.WRITE_DATA(c,UTL_TCP.CRLF);
END LOOP;
UTL_SMTP.WRITE_DATA(c, chr(13)||'-Sent by the batch process.');
UTL_SMTP.CLOSE_DATA(c);
UTL_SMTP.QUIT(c);
EXCEPTION
WHEN utl_smtp.transient_error OR utl_smtp.permanent_error THEN
BEGIN
UTL_SMTP.QUIT(c);
EXCEPTION
WHEN UTL_SMTP.TRANSIENT_ERROR OR UTL_SMTP.PERMANENT_ERROR THEN
NULL; -- When the SMTP server is down or unavailable, we don't have
-- a connection to the server. The QUIT call will raise an
-- exception that we can ignore.
END;
raise_application_error(-20000,
'Failed to send mail due to the following error: ' || sqlerrm);
END;
END IF;
END;
现在我得到的错误是:
SP2-0027: Input is too long (> 2499 characters) - line ignored
SQL> SP2-0734: unknown command beginning "ggg..." - rest of line ignored.
SQL> SP2-0734: unknown command beginning "ddd..." - rest of line ignored.
SQL> SP2-0734: unknown command beginning "eee..." - rest of line ignored.
SQL> SP2-0734: unknown command beginning "nnn..." - rest of line ignored.
SP2-0044: For a list of known commands enter HELP
and to leave enter EXIT.
SQL> SP2-0734: unknown command beginning "hfhf..." - rest of line ignored.
SQL> Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
With the Partitioning, Oracle Label Security, OLAP, Data Mining
and Real Application Testing options
我查了一下SP2-0027,我收集到输入行超过2499个字符。我的所有输入行都没有这么多字符,SQL文件本身的总字符数大约是4000。
我不知道UTL_SMTP的内部实现是否在幕后传递了一些数据。或者如果还有其他事情发生。
使用TOAD时运行完美。
有人可以帮忙吗?
答案 0 :(得分:0)
我想我找到了答案:
我所要做的就是将shell脚本执行的SQL文件拆分为2个文件,并将volia`分解为:D
@tbone:fyi&amp;谢谢你的帮助!