Copying BLOB content to a OS file using BFILE
802704Oct 3 2010 — edited Oct 4 2010Hey people, I am trying to develop a procedure for copying the contents of a blob to a file on my operating system..But I am facing some problem in the code of procedure....
desc blob_content
Name Null? Type
----------------------------------------- -------- ----------------------------
ID NOT NULL NUMBER(38)
BLOB_COLUMN NOT NULL BLOB
------------------------------------------------------------------------------------------------------
CREATE OR REPLACE DIRECTORY PHOTO_FOLDER AS 'c:\sample_files';
------------------------------------------------------------------------------------------------------
CREATE OR REPLACE PROCEDURE get_photo
(p_id NUMBER)
AS
f_photo BFILE;
b_photo BLOB;
buf RAW(32767);
BEGIN
-- find where the photo's pointer is located.
f_photo := bfilename('PHOTO_FOLDER','temp.jpg');
-- open the photo as write option.
dbms_lob.open(f_photo, DBMS_LOB.FILE_READWRITE);
-- load the photo into column photo.
SELECT blob_column into b_photo
FROM blob_content
WHERE id = p_id;
read(b_photo,dbms_lob.getlength(b_photo),1,buf);
-- close the photo's pointer.
write(f_photo,dbms_lob.getlength(b_photo),1,buf);
dbms_lob.fileclose(f_photo);
-- Save the loaded photo record.
COMMIT;
EXCEPTION
-- Check for your error messages
WHEN others THEN
dbms_output.put_line('*** ERROR *** Check you procedure.');
END;
-- My Question is how to open a bfile in write mode and then how to write content of blob into location pointed by the bfile.....
While creating this procedure the error I get is :
LINE/COL ERROR
12/1 PL/SQL: Statement ignored
12/33 PLS-00302: component 'FILE_READWRITE' must be declared
19/1 PL/SQL: Statement ignored
19/1 PLS-00201: identifier 'READ' must be declared
22/1 PL/SQL: Statement ignored
22/1 PLS-00201: identifier 'WRITE' must be declared
Edited by: 799701 on Oct 3, 2010 1:18 PM
Edited by: 799701 on Oct 3, 2010 1:19 PM