Call now: 252-767-6166  
Oracle Training Oracle Support Development Oracle Apps

 E-mail Us
 Oracle Articles
New Oracle Articles

 Oracle Training
 Oracle Tips

 Oracle Forum
 Class Catalog

 Remote DBA
 Oracle Tuning
 Emergency 911
 RAC Support
 Apps Support
 Oracle Support

 SQL Tuning

 Oracle UNIX
 Oracle Linux
 Remote s
 Remote plans
 Application Server

 Oracle Forms
 Oracle Portal
 App Upgrades
 SQL Server
 Oracle Concepts
 Software Support

 Remote S


 Consulting Staff
 Consulting Prices
 Help Wanted!


 Oracle Posters
 Oracle Books

 Oracle Scripts

Don Burleson Blog 








Writing Oracle BLOB to OS file

Oracle Database Tips by Burleson Consulting


It's easy to write a BLOB (CLOB) to an OS file using PL/SQL.

Note that the PL/SQL below uses to read the BLOB or CLOB from Oracle, and utl_file.put_raw to write the blob to the file.

For more details on writing advanced PL/SQL, see Dr. Halls book "PL/SQL Tuning".

Here is non-working psuedocode that demonstrates the concept:

CREATE OR REPLACE PROCEDURE extract_file(product_id in number) IS

vblob BLOB;
vstart NUMBER := 1;
bytelen NUMBER := 32000;
my_vr RAW(32000);

l_output utl_file.file_type;


-- define output directory
l_output := utl_file.fopen('DIR_TEMP', 'filename','wb', 32760);

vstart := 1;
bytelen := 32000;

-- get length of blob
SELECT dbms_lob.getlength(productblob)
INTO len
FROM products
WHERE id = product_id;

-- save blob length
x := len;

-- select blob into variable
SELECT product_blob
INTO vblob
FROM products
WHERE id = product_id;

-- if small enough for a single write
IF len < 32760 THEN
ELSE -- write in pieces
vstart := 1;
WHILE vstart < len and bytelen > 0


   -- set the start position for the next cut
   vstart := vstart + bytelen;

   -- set the end position if less than 32000 bytes
   x := x - bytelen;
   IF x < 32000 THEN
      bytelen := x;
   END IF;
end loop;


Oracle consulting and training



Oracle Training at Sea
oracle dba poster

Follow us on Twitter 
Oracle performance tuning software 
Oracle Linux poster


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.


Burleson Consulting

The Oracle of Database Support

Oracle Performance Tuning

Remote DBA Services


Copyright © 1996 -  2020

All rights reserved by Burleson

Oracle ® is the registered trademark of Oracle Corporation.