在存储过程中传递变量

wrrgggsh  于 2022-10-04  发布在  Oracle
关注(0)|答案(1)|浏览(208)

我有一个工作存储过程,如下所示

Declare
      l_id number;
    begin
      l_id := apex_mail.send( 
        p_to => 'test@test.com', 
        p_from => 'test@test.com', 
        p_subj => 'Mail from APEX with attachment', 
        p_body => 'Please review the attachment.', 
        p_body_html => 'Please review the attachment.'
      );
      apex_mail.add_attachment( 
         p_mail_id    => l_id,
        p_attachment => p_output_blob, 
        p_filename   => p_output_filename, 
        p_mime_type  => p_output_mime_type
      );
     end;

此程序在下载后通过电子邮件发送附件,这正是我想要的。然而,这个问题是,我希望p_to根据我的表TEMP_FEES中的新email_address进行更改。该表一次将有一个记录/电子邮件地址。

我试过了

Declare
  l_id number;
begin
    FOR m IN (SELECT parent_email
            FROM TEMP_FEES
           )
LOOP
  apex_mail.send( p_to => m.parent_email,
                  p_from => 'test@test.com',
                  p_body => 'test',
                  p_subj => 'invoice'
  );
  apex_mail.add_attachment( 
    p_mail_id    => l_id, 
    p_attachment => p_output_blob, 
    p_filename   => p_output_filename, 
    p_mime_type  => p_output_mime_type
  );

  END LOOP;  
end

但我收到了一个错误

ORA-20022:为参数P_mail_id提供空值

当我提交表格时。

我能得到一些关于如何解决这个问题的建议吗?

1aaf6o9v

1aaf6o9v1#

不确定这是否可能是问题所在,但在第二个示例中,您没有将过程调用输出赋给变量l_id。因此,代码应如下所示:

Declare
  l_id number;
begin
    FOR m IN (SELECT parent_email
            FROM TEMP_FEES
           )
LOOP
  l_id := apex_mail.send( p_to => m.parent_email,
                  p_from => 'test@test.com',
                  p_body => 'test',
                  p_subj => 'invoice'
  );
  apex_mail.add_attachment( 
    p_mail_id    => l_id, 
    p_attachment => p_output_blob, 
    p_filename   => p_output_filename, 
    p_mime_type  => p_output_mime_type
  );

  END LOOP;  
end;

希望这能帮上忙。

谢谢Arnab P

相关问题