PL / SQL:在存储过程中获取错误ORA-006550 PLS-00306

时间:2017-01-26 21:57:02

标签: oracle plsql bulk-collect

我开发了一个存储过程,可以发送一次通知电子邮件,这样我就不会从我的显式游标中收到100,000封单独的电子邮件," crs"。 存储过程名称是" a_test_email"。我创建了一个名为" crs"的显式游标。游标查询user_objects以检查数据库中是否有任何对象是INVALID。我遇到的问题是" a_test_email"存储过程循环以发送电子邮件。 "批量收集"获取光标中的所有记录" crs"然后发送一封电子邮件,在一封电子邮件中显示所有行(即记录)。但是,我不断收到错误ORA-0065550 PLS-00306。我不确定我做错了什么。请帮助我用" a_test_email"更正此问题。存储过程。

create or replace procedure a_test_email is

TYPE user_obj_tbl IS TABLE OF user_objects%ROWTYPE;
messages    user_obj_tbl;
v_email_body  varchar2(32767) := 'Oracle found ';

cursor crs is
 select *
 from user_objects
 where status = 'INVALID';

Begin

open crs;

loop
  fetch crs bulk collect into messages limit 100;
   exit when messages.count = 0;

  for indx in 1 .. messages.COUNT
  loop
    v_email_body := v_email_body||', '||messages(indx);
  end loop;
end loop;

v_email_body := v_email_body ||' object in your database. Please
troubleshoot issue. Thank you.';

email_format_test(p_to => 'test_email_1@testing.com',
                  p_cc => 'test_email_2@testing.com',
                  p_from => 'test_email_3@testing.com',
                  p_subject => 'INVALID OBJECTS '||messages.COUNT,
                  p_message => v_email_body,
                  p_smpt_host => '11.11.111.11'
                 );
 close crs;

 end;

---以下是发送电子邮件的存储过程---

create or replace procedure email_format_test(p_to => IN varchar2, 
                                              p_cc => IN varchar2, 
                                              p_from => IN varchar2, 
                                              p_subject => IN varchar2, 
                                              p_message => IN varchar2, 
                                              p_smpt_host => IN varchar2, 
                                              p_smpt_port => IN number
                                              default 25) 
as 
v_mail_conn utl_smtp.connection; 
BEGIN 
v_mail_conn := utl_smtp.open_connection(p_smtp_host, p_smtp_port); 
utl_smtp.helo(v_mail_conn, p_smtp_host); 
utl_smtp.mail(v_mail_conn, p_from); 
utl_smtp.rcpt(v_mail_conn, p_to); 

utl_smtp.open_data(v_mail_conn); 

utl_smtp.write_data(v_mail_conn, 'Date: '||TO_CHAR(sysdate, 'DD-MON-YYYY
HH12:MI:SS')||utl_tcp.crlf); 
utl_smtp.write_data(v_mail_conn, 'To: '||p_to||utl_tcp.crlf); 
utl_smtp.write_data(v_mail_conn, 'From: '||p_from||utl_tcp.crlf); 
utl_smtp.write_data(v_mail_conn, 'Subject: '||p_subject||utl_tcp.crlf); 
utl_smtp.write_data(v_mail_conn, 'Reply
To: '||p_from||utl_tcp.crlf||utl_tcp.crlf); 

utl_smtp.write_data(v_mail_conn, p_message ||utl_tcp.crlf||utl_tcp.crlf); 
utl_smtp.close_data(v_mail_conn); 

utl_smtp.quit(v_mail_conn); 
END; 

3 个答案:

答案 0 :(得分:2)

我认为问题在这里。

v_email_body := v_email_body||', '||messages(indx);

Oracle无法找到将字符串与rowtype连接的函数。 messages(indx)是user_object%rowtype。

试试这个。 v_email_body := v_email_body||', '||messages(indx).OBJECT_NAME;

答案 1 :(得分:0)

您的程序语法无效。在声明变量时,您不会使用=>

将其更改为:

create or replace procedure email_format_test(p_to IN varchar2, 
                                              p_cc IN varchar2, 
                                              p_from IN varchar2, 
                                              p_subject IN varchar2, 
                                              p_message IN varchar2, 
                                              p_smpt_host IN varchar2, 
                                              p_smpt_port IN number
                                              default 25) 

答案 2 :(得分:-1)

您正在使用6个参数调用该过程,但它需要7个参数(缺少p_smpt_port参数)。