?
Solved

Storing and Reading BFILE data (or BLOB)

Posted on 2005-03-23
9
Medium Priority
?
942 Views
Last Modified: 2013-12-11
I need to store two values in a table: customerID and cover letter.

1) I'm assuming the cover letter should be stored as a BFILE data type, but if anyone can enlighten me as to whether storing it as a BLOB or CLOB would be better, I'm all ears

2) Can someone post some sample code for reading this BFILE data back out of the table?  I was able to insert the record, but I can't get it back out now.
0
Comment
Question by:CreateObject
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +1
9 Comments
 
LVL 7

Accepted Solution

by:
Nievergelt earned 336 total points
ID: 13619385
1) Use BLOB, if you want to have the document being part of the transaction or you prefer to access the data more directly or want to avoid the additional setup required for BFILE (CREATE DIRECTORY etc.).
CLOB tells Oracle to treat the data as character. The cover letter probably is dome binary document and therefore a "binary large object". Character data may be translated depending on your language and character set configuration. BLOB data will be unchanged for all possible configurations.

2) Please supply some more information:
    - Which programming language?
    - Do you need to have to get the document data in your program or do you for example only want to copy the file?
0
 
LVL 5

Author Comment

by:CreateObject
ID: 13622888
>> - Which programming language?

PL-SQL

>> - Do you need to have to get the document data in your
>> program or do you for example only want to copy the file?

Have to read the document data and display it in a web page.
0
 
LVL 7

Expert Comment

by:Nievergelt
ID: 13628847
For PL/SQL you will need to use PL/SQL Package DBMS_LOB.

Have a look at http://www.stanford.edu/dept/itss/docs/oracle/9i/appdev.920/a96612/d_lob.htm#ARPLS020
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 77

Assisted Solution

by:slightwv (䄆 Netminder)
slightwv (䄆 Netminder) earned 332 total points
ID: 13632282
Whether you store it externally or in a blob depends a lot on your requirements.  There are pros and cons for each.
For example:
storing external:  
  con- File can be removed from OS and Oracle won't know.
  con- Backup and recovery issues and data sync on recovery.
  pro- If you only need limited access to the contents from within the DB.

storing in BLOB:  just reverse the pros and cons above.

To get it back to the filesystem:
http://www.experts-exchange.com/Databases/Oracle/Q_10109815.html
0
 
LVL 48

Expert Comment

by:schwertner
ID: 13643249
0
 
LVL 5

Author Comment

by:CreateObject
ID: 13643958
If someone could post some sample code for retrieving and displaying the BLOB field, that would be great.
0
 
LVL 48

Assisted Solution

by:schwertner
schwertner earned 332 total points
ID: 13650136
I found this but haven't tried it.
How to load and display images from database:

CREATE TABLE IMAGES
(
  IMAGE_NAME  VARCHAR2(30)  primary key,
  MIME_TYPE   VARCHAR2(30),
  CONTENT     BLOB
)

CREATE OR REPLACE PACKAGE BODY IMAGE AS

PROCEDURE load(filename VARCHAR2) AS
  f_lob BFILE;
  b_lob BLOB;
  image_name VARCHAR2(30);
  mime_type VARCHAR2(30);
  dot_pos NUMBER;
BEGIN
    dot_pos := INSTR(filename,'.');
    image_name := filename; --SUBSTR(filename,1,dot_pos-1);
    mime_type := 'image/'||SUBSTR( filename,dot_pos+1,length(filename) );

    INSERT INTO images values(image_name,mime_type,empty_blob() )
           RETURN content INTO b_lob;
    f_lob := BFILENAME('SOURCE_DIR',filename);
    dbms_lob.fileopen(f_lob,dbms_lob.file_readonly);
    dbms_lob.loadfromfile(b_lob,f_lob,dbms_lob.getlength(f_lob) );
    dbms_lob.fileclose(f_lob);
    COMMIT;
END;
/*=====*/
PROCEDURE get(name varchar2) AS
  vblob     BLOB;
  mime_type VARCHAR2(30);
BEGIN
  select content,mime_type
  into vblob,mime_type
  from images
  where image_name=name;
  owa_util.mime_header(mime_type, false);
  owa_util.http_header_close;
  wpg_docload.download_file(vblob);
    exception when others then
          htp.p(sqlcode || sqlerrm);
END;
/*=====*/
END;
/

SQL> create directory source_dir as '/mydir';
if you have an image file in /mydir/toolbar.gif

SQL> exec image.load('toolbar.gif');

create procedure test as
begin
  htp.p('<img src=image.get?name=toobar.gif>');
end;
/
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Working with Network Access Control Lists in Oracle 11g (part 1) Part 2: http://www.e-e.com/A_9074.html So, you upgraded to a shiny new 11g database and all of a sudden every program that used UTL_MAIL, UTL_SMTP, UTL_TCP, UTL_HTTP or any oth…
From implementing a password expiration date, to datatype conversions and file export options, these are some useful settings I've found in Jasper Server.
Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Suggested Courses

766 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question