我正在oracle中编写一个pl / sql程序来发送带有多个附件的自动电子邮件我编写了一个我正在使用以下逻辑的过程:
TYPE attach_info IS RECORD (
attach_name VARCHAR2(100),
data_type VARCHAR2(100) DEFAULT 'text/plain',
attach_content BLOB DEFAULT NULL
);
TYPE array_attachments IS TABLE OF attach_info;
attachments array_attachments := array_attachments();
这里我定义的类型比下面的定义数组大小
attachments.extend(3);
以下代码我检索附件信息并将其发送给发送电子邮件
FOR i IN attachments.FIRST .. attachments.LAST
LOOP
-- Attach info
UTL_SMTP.write_raw_data(l_mail_conn, utl_raw.cast_to_raw('--' || l_boundary || UTL_TCP.crlf));
UTL_SMTP.write_raw_data(l_mail_conn, utl_raw.cast_to_raw('Content-Type: ' || attachments(i).data_type
|| ' name="'|| attachments(i).attach_name || '"' || UTL_TCP.crlf));
UTL_SMTP.write_data(l_mail_conn, 'Content-Transfer-Encoding: base64' || UTL_TCP.crlf);
UTL_SMTP.write_raw_data(l_mail_conn, utl_raw.cast_to_raw('Content-Disposition: attachment; filename="'
|| attachments(i).attach_name || '"' || UTL_TCP.crlf || UTL_TCP.crlf));
-- Attach body
FOR j IN 0 .. TRUNC((DBMS_LOB.getlength(attachments(i).attach_content) - 1 )/l_step) LOOP
UTL_SMTP.write_data(l_mail_conn, UTL_RAW.cast_to_varchar2(UTL_ENCODE.base64_encode(DBMS_LOB.substr(attachments(i).attach_content, l_step, j * l_step + 1))));
END LOOP;
UTL_SMTP.write_data(l_mail_conn, UTL_TCP.crlf || UTL_TCP.crlf);
END LOOP;
现在我想让这个过程变得通用,我可以在很多地方使用这个过程, 所以我的问题是我如何定义这种类型的附件,我如何填充然后如何在过程中传递这个附件数组,以便我可以发送它们。
答案 0 :(得分:0)
您可以使用该类型为PLSQL函数或过程
创建参数procedure send(p_address varchar2,p_subject varchar2, p_attachments array_attachments)