【发布时间】:2016-12-28 14:20:40
【问题描述】:
假设我有两个文件名相同的文件sample.xlsx
在两个单独的目录中 u1\data\out1\ 和 u2\data\out2\
这两个目录已经分别以EXT_OUT1 和EXT_OUT2 进入DBA_DIRECTORIES。
我想使用UTL_MAIL.SEND_ATTACH_RAW从EXT_OUT1发送sample.xlsx,
如何将其正确传递给attachment 参数?
示例匿名块(注意 cmets):
DECLARE
vInHandle utl_file.file_type;
l_sender varchar2(100) := 'SO@SO.com';
l_recipients varchar2(100) := 'migs.isip.23@gmail.com';
l_subject varchar2(100) := 'Employee Roster Report';
l_message varchar2(100) := 'Hello';
l_attachment raw;
l_directory varchar2(100) := 'EXT_OUT1';
fname varchar2(100) := 'sample.xlsx';
BEGIN
/* how put RAW data into l_attachment here? */
--vInHandle := utl_file.fopen(l_directory, fname, 'R'); -- If i'm not mistaken, this reads the File from the specified directory
--utl_file.get_raw(); -- not sure what parameters i should pass
--utl_file.fclose(vInHandle); -- ?
UTL_MAIL.SEND_ATTACH_RAW
(
sender => l_sender
, recipients => l_recipients
, subject => l_subject
, message => l_message
, attachment => l_attachment
, att_filename => 'clouds.jpg'
);
EXCEPTION
WHEN OTHERS THEN
raise_application_error(-20001,'The following error has occured: ' || sqlerrm);
END;
【问题讨论】:
-
当你运行它时会发生什么?第 5 个参数应该是 RAW 值,而不是字符串;第 6 个是电子邮件中的附件的名称。它不查看任何目录。 See a demo here.
-
嗨@AlexPoole,很抱歉,我编辑了这个问题,请告诉我应该如何将
l_attachment传递给attachment参数。 -
您只能使用此过程附加一个文档。另请注意,RAW 的大小限制为 32k。这足以满足您的需求吗?
-
嗨@WernfriedDomscheit,是的,我只会附上一个
xlsx文件。可能在 4 MB 左右。 32k 是指 32 KB? -
在这种情况下,您必须使用低级包UTL_SMTP。使用此帖子获取起点:stackoverflow.com/questions/34691487/… 以附加 BLOB google for "utl_smtp blob attachment"