<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Technology Articles &#187; Load BLOB from File</title>
	<atom:link href="http://technologydribble.info/tag/load-blob-from-file/feed/" rel="self" type="application/rss+xml" />
	<link>http://technologydribble.info</link>
	<description>Articles About Technology</description>
	<lastBuildDate>Mon, 19 Dec 2011 11:11:23 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Loading a File Into a BLOB Object in Oracle</title>
		<link>http://technologydribble.info/2009/08/18/loading-a-file-into-a-blob-object-in-oracle/</link>
		<comments>http://technologydribble.info/2009/08/18/loading-a-file-into-a-blob-object-in-oracle/#comments</comments>
		<pubDate>Tue, 18 Aug 2009 22:57:34 +0000</pubDate>
		<dc:creator>ryelpango</dc:creator>
				<category><![CDATA[BLOB]]></category>
		<category><![CDATA[Load File Into BLOB]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[PL/SQL]]></category>
		<category><![CDATA[Load BLOB from File]]></category>
		<category><![CDATA[Write BLOB from OS File]]></category>

		<guid isPermaLink="false">http://technologydribble.info/?p=142</guid>
		<description><![CDATA[Loading a file into a BLOB object in Oracle is easy. All we need to do is use the DBMS_LOB package to load the file into a temporary LOB object. This is demonstrated in the following example. This example assumes &#8230; <a href="http://technologydribble.info/2009/08/18/loading-a-file-into-a-blob-object-in-oracle/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Loading a file into a BLOB object in Oracle is easy. All we need to do is use the DBMS_LOB package to load the file into a temporary LOB object. This is demonstrated in the following example.</p>
<p>This example assumes that you have a directory object set up where the files are stored. In this example the following object is used:</p>
<p><code>CREATE DIRECTORY FILEUPLOADS AS '/home_new/dmt/public_html/fileuploads';</code></p>
<p>Use the following function to load a file based on the filename parameter and return the BLOB reference for processing:</p>
<pre>

CREATE OR REPLACE FUNCTION loadBlobFromFile(p_file_name VARCHAR2) RETURN BLOB AS
  dest_loc  BLOB := empty_blob();
  src_loc   BFILE := BFILENAME('FILEUPLOADS', p_file_name);
BEGIN
  -- Open source binary file from OS
  DBMS_LOB.OPEN(src_loc, DBMS_LOB.LOB_READONLY);

  -- Create temporary LOB object
  DBMS_LOB.CREATETEMPORARY(
        lob_loc => dest_loc
      , cache   => true
      , dur     => dbms_lob.session
  );

  -- Open temporary lob
  DBMS_LOB.OPEN(dest_loc, DBMS_LOB.LOB_READWRITE);

  -- Load binary file into temporary LOB
  DBMS_LOB.LOADFROMFILE(
        dest_lob => dest_loc
      , src_lob  => src_loc
      , amount   => DBMS_LOB.getLength(src_loc));

  -- Close lob objects
  DBMS_LOB.CLOSE(dest_loc);
  DBMS_LOB.CLOSE(src_loc);

  -- Return temporary LOB object
  RETURN dest_loc;
END loadBlobFromFile;
/
</pre>
<p>Easy as that.</p>
]]></content:encoded>
			<wfw:commentRss>http://technologydribble.info/2009/08/18/loading-a-file-into-a-blob-object-in-oracle/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

