Hello,
I am trying to display the content of a PDF (BFILE) with SQL Developer but I got only artifacts.
Here is my code:
CREATE TABLE MY_DOC
( ID NUMBER PRIMARY KEY,
FILE_NAME VARCHAR2(255 BYTE),
UPLOAD_DATE VARCHAR2(10 BYTE),
FILESIZE VARCHAR2(20 BYTE),
FILETYPE VARCHAR2(5 BYTE),
CONTENT BFILE,
CREATION_DATE DATE DEFAULT sysdate NOT NULL ENABLE,
MODIFICATION_DATE DATE,
ACCESSED_DATE DATE,
)
CREATE INDEX MY_DOC_IDX ON MY_DOC (CONTENT)
INDEXTYPE IS CTXSYS.CONTEXT ;
The procedure I am using to display the file is:
CREATE OR REPLACE PROCEDURE displayBFILE_proc(p_file_name VARCHAR2) IS
Lob_loc BFILE;
Buffer RAW(1024);
Amount BINARY_INTEGER := 1024;
Position INTEGER := 1;
BEGIN
/* Select the LOB: */
SELECT content INTO Lob_loc
FROM My_Doc WHERE file_name = p_file_name ;
/* Opening the BFILE: */
DBMS_LOB.OPEN (Lob_loc, DBMS_LOB.LOB_READONLY);
LOOP
DBMS_LOB.READ (Lob_loc, Amount, Position, Buffer);
/* Display the buffer contents: */
DBMS_OUTPUT.PUT_LINE(utl_raw.cast_to_varchar2(Buffer));
Position := Position + Amount;
END LOOP;
/* Closing the BFILE: */
DBMS_LOB.CLOSE (Lob_loc);
EXCEPTION
WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE('End of data');
END; Can you tell me what am I doing wrong, please?
Thank you very much.
You're reading a binary file! You can't just spit the contents out as text. You need to use a program which can recognize the PDF file format.
SQL Developer has in-built support for image and text BLOBs:
http://www.thatjeffsmith.com/archive/2012/01/sql-developer-quick-tip-blobs-and-images/ But not PDFs that I'm aware of. You can download the file to your machine using a similar process to the one Jeff describes in the link above (click the pencil icon in the results data grid). But select "Download" then save it to your desktop.