我有一个 PL/SQL 电子邮件包,如下所示:
create or replace package mail_pkg
as
PRAGMA SERIALLY_REUSABLE; -- this avoids ORA-04068 error
type array is table of varchar2(255);
procedure send( p_sender_email in varchar2,
p_from in varchar2 default null,
p_to in array default array(),
p_cc in array default array(),
p_bcc in array default array(),
p_subject in varchar2 default null,
p_body in clob default null);
示例用法是:
begin
mail_pkg.send( p_sender_email => 'tim@company1.com',
p_from => 'John Smith <johns@company2.com>',
p_to => mail_pkg.array( 'greg@company3.com','sarah@company4.com'),
p_cc => mail_pkg.array( 'admin@company5.com' ),
p_bcc => mail_pkg.array( 'sue@company5.com' ),
p_subject => 'This is my subject',
p_body => 'Hello, this is the mail you requested.' );
end;
[注意:对于任何寻找电子邮件包的人,这是我从中获得的链接: http://asktom.oracle.com/pls/apex/f?p=100:11:0::::P11_QUESTION_ID: 255615160805 ]
我想用它来发送电子邮件,但是输入中的电子邮件地址p_to
必须是动态输入的。也就是说,我不能像上面那样对它们进行硬编码。它们需要来自 SELECT 语句。我熟悉编写 select 语句,但我不知道如何将 selecte 语句的结果转换为可以包含在
p_to => mail_pkg.array( WHAT GOES HERE??? ),
代码。
任何人都知道我如何连接一个 SELECT 语句(它返回一些电子邮件地址)来使用这个包?
更新:
根据以下反馈,解决方案是:
create or replace procedure send_email (
in_name IN varchar2
)
AS
v_body clob;
v_to_array mail_pkg.array := mail_pkg.array();
v_counter int := 1;
BEGIN
FOR r IN (SELECT person_email FROM email_table WHERE company_name=in_name) LOOP
v_to_array.extend;
v_to_array(v_counter) := r.person_email;
v_counter := v_counter +1;
END LOOP;
-- send email
mail_pkg.send( p_sender_email => 'sam@company2.com',
p_from => 'admin@company2.com',
p_to => v_to_array,
p_bcc => mail_pkg.array( 'tim@company3.com' ),
p_subject => 'the subject line goes here',
p_body => 'This is the body message.' );
END send_email;