【问题标题】:passing a variable in a stored procedure在存储过程中传递变量
【发布时间】:2022-09-27 18:35:25
【问题描述】:

我有一个有效的存储过程,如下所示

 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 提供了空值

当我提交表格时。

我可以就如何解决这个问题获得任何建议吗?

  • 您是否验证了 TEMP_FEES.PARENT_EMAIL 是否为空?如果您刚刚更新了该表中的行,您是犯罪这些变化?
  • 是的,parent_email 不为空,是的,更改已提交
  • 在第二个块中,当您调用 apex_mail.send 时,您不再为 l_id 赋值。因此,当您调用 add_attachment 时,l_id 仍然是 null。因此,p_mail_idnull

标签: oracle oracle11g oracle-apex oracle-apex-5.1


【解决方案1】:

不确定这是否是问题所在,但在第二个示例中,您没有将过程调用输出分配给变量 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;

希望这可以帮助。

谢谢 阿纳布

【讨论】:

    猜你喜欢
    • 2015-04-05
    • 2011-09-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-20
    • 1970-01-01
    相关资源
    最近更新 更多