I have a PL/SQL email package that looks like:
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);
Example usage would be:
begin
mail_pkg.send( p_sender_email => '[email protected]',
p_from => 'John Smith <[email protected]>',
p_to => mail_pkg.array( '[email protected]','[email protected]'),
p_cc => mail_pkg.array( '[email protected]' ),
p_bcc => mail_pkg.array( '[email protected]' ),
p_subject => 'This is my subject',
p_body => 'Hello, this is the mail you requested.' );
end;
[note: for anyone looking for an e-mail package, here's the link I got it from: http://asktom.oracle.com/pls/apex/f?p=100:11:0::::P11_QUESTION_ID:255615160805 ]
I want to use it to send an email, but the email addresses in the p_to input must be input dynamically. That is, I can't hardcode them like above. They need to come from a SELECT statement. I'm familiar with writing select statements, but I don't know how to to get the result of the selecte statement into a format that I can include in the
p_to => mail_pkg.array( WHAT GOES HERE??? ),
code.
Anyone know how I can connect a SELECT statement (which returns some email addresses) to work with this package?
UPDATE:
Based on feedback below, the solution is:
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 => '[email protected]',
p_from => '[email protected]',
p_to => v_to_array,
p_bcc => mail_pkg.array( '[email protected]' ),
p_subject => 'the subject line goes here',
p_body => 'This is the body message.' );
END send_email;