Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Storing and Reading BFILE data (or BLOB)

Posted on 2005-03-23
9
Medium Priority
?
944 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
  • 2
  • 2
  • 2
  • +1
7 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 78

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

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

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…
How to Unravel a Tricky Query Introduction If you browse through the Oracle zones or any of the other database-related zones you'll come across some complicated solutions and sometimes you'll just have to wonder how anyone came up with them.  …
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 video shows how to recover a database from a user managed backup
Suggested Courses
Course of the Month13 days, 13 hours left to enroll

581 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