Question:
We have a PDF in a BLOB column and when saved on desktop,
say as 123.pdf, we are able to open and view the contents
correctly.
Now we want to send it to mail recipients
as an attachment. Below is the table description and PDF
column is BLOB type. Also find the code written so far. I'm
receiving mail with PDF attachment but unable to open the
file column. When saved the PDF from mail to desktop, it is
ZERO bytes.
CREATE
TABLE XXCFI.XX_PDF2
(
CUSTOMER_TRX_ID INTEGER,
TRX_NUMBER VARCHAR2(40 BYTE),
WEBSERVICE_RESPONSE_DATA CLOB,
PDF BLOB,
REQUEST_ID INTEGER,
ORDER_NUMBER VARCHAR2(40 BYTE),
CREATION_DATE DATE,
PDF2 BLOB
)
Code :
DECLARE
v_connection utl_smtp.connection;
c_mime_boundary CONSTANT
VARCHAR2(256) := '-----AABCDEFBBCCC0123456789DE';
v_clob blob := empty_blob ();
v_len INTEGER;
v_index INTEGER;
l_raw raw(57);
l_len INTEGER := 0;
l_idx INTEGER := 1;
l_trx_id NUMBER;
l_buff_size INTEGER := 57;
l_filename VARCHAR2(20);
BEGIN
dbms_output.put_line(1);
SELECT pdf, customer_trx_id
INTO v_clob,l_trx_id
FROM xx_pdf2
WHERE ROWNUM < 2;
l_filename
:= l_trx_id || '.pdf';
dbms_output.put_line(2);
v_connection :=
utl_smtp.open_connection('outbound.mycompany.com',25);
utl_smtp.helo(v_connection,'outbound.mycompany.com');
utl_smtp.mail(v_connection,'noreply@mycompany.com');
utl_smtp.rcpt(v_connection,'abcd@mycompany.com');
utl_smtp.open_data(v_connection);
dbms_output.put_line(3);
utl_smtp.write_data( v_connection,
'From: ' || 'noreply@mycompany.com' || utl_tcp.crlf );
utl_smtp.write_data( v_connection,
'To: '|| 'abcd@mycompany.com' || utl_tcp.crlf );
utl_smtp.write_data(v_connection,'Subject:
test subject'|| utl_tcp.crlf);
utl_smtp.write_data(v_connection,'MIME-Version:
3.1'|| utl_tcp.crlf);
dbms_output.put_line(4);
utl_smtp.write_data( v_connection,
'Content-Type: multipart/mixed; boundary="'||
c_mime_boundary|| '"' || utl_tcp.crlf );
utl_smtp.write_data(v_connection,utl_tcp.crlf);
utl_smtp.write_data(v_connection,'This
is a multi-part message in MIME format.' || utl_tcp.crlf);
dbms_output.put_line(5);
utl_smtp.write_data( v_connection,
'--' || c_mime_boundary|| utl_tcp.crlf );
utl_smtp.write_data(v_connection,'Content-Type:
application/pdf'|| utl_tcp.crlf);
dbms_output.put_line(6);
-- Set up attachment header
utl_smtp.write_data(v_connection,
'Content-Disposition: attachment; filename="' || l_filename
|| '"' || utl_tcp.crlf);
utl_smtp.write_data(v_connection,utl_tcp.crlf);
-- Write
attachment contents
dbms_output.put_line(7);
v_len := dbms_lob.getlength(v_clob);
dbms_output.put_line( 7.1 || ' -
'|| v_len );
v_index :=
1;
dbms_output.put_line(7.2);
WHILE v_index <= v_len LOOP
utl_smtp.write_data( v_connection,dbms_lob.substr(v_clob,64000,v_index)
);
v_index := v_index + 64000;
END LOOP;
dbms_output.put_line(9);
--
-- End attachment
utl_smtp.write_data(v_connection,utl_tcp.crlf);
utl_smtp.write_data( v_connection,
'--'|| c_mime_boundary || '--'|| utl_tcp.crlf);
dbms_output.put_line(10);
utl_smtp.close_data(v_connection);
utl_smtp.quit(v_connection);
dbms_output.put_line(11);
EXCEPTION
WHEN others THEN
dbms_output.put_line(dbms_utility.format_error_stack);
END;
Answer: These notes explain how to
create, store and retrieve a PDF in an Oracle table columns:
|
|
|
Oracle Training from Don Burleson
The best on site
"Oracle
training classes" are just a phone call away! You can get personalized Oracle training by Donald Burleson, right at your shop!

|
|
|

|
|
Burleson is the American Team

Note:
This Oracle
documentation was created as a support and Oracle training reference for use by our
DBA performance tuning consulting professionals.
Feel free to ask questions on our
Oracle forum.
Verify
experience!
Anyone
considering using the services of an Oracle support expert should
independently investigate their credentials and experience, and not rely on
advertisements and self-proclaimed expertise. All legitimate Oracle experts
publish
their Oracle
qualifications.
Errata?
Oracle technology is changing and we
strive to update our BC Oracle support information. If you find an error
or have a suggestion for improving our content, we would appreciate your
feedback. Just
e-mail:
and include the URL for the page.
Copyright © 1996 - 2020
All rights reserved by
Burleson
Oracle ®
is the registered trademark of Oracle Corporation.
|
|