<?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>twit88.com &#187; PL/SQL</title>
	<atom:link href="http://twit88.com/blog/category/plsql/feed/" rel="self" type="application/rss+xml" />
	<link>http://twit88.com/blog</link>
	<description>New SMS Library at http://twit88.com/platform/projects/show/messagingtoolkit !</description>
	<lastBuildDate>Wed, 08 Sep 2010 08:23:21 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Dynamically Import Data from Different Oracle Databases from Web Application</title>
		<link>http://twit88.com/blog/2007/10/02/dynamically-import-data-from-different-oracle-databases-from-web-application/</link>
		<comments>http://twit88.com/blog/2007/10/02/dynamically-import-data-from-different-oracle-databases-from-web-application/#comments</comments>
		<pubDate>Tue, 02 Oct 2007 14:25:22 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Oracle]]></category>
		<category><![CDATA[PL/SQL]]></category>

		<guid isPermaLink="false">http://twit88.com/blog/2007/10/02/dynamically-import-data-from-different-oracle-databases-from-web-application/</guid>
		<description><![CDATA[Download Source Sometimes back when I was involved in a project I faced the challenge to import data from different Oracle databases synchronously within my Java web application. Performance is the key issue. The import has to be completed in a short time frame according to the SLA. Of course I can dynamically create JDBC [...]]]></description>
			<content:encoded><![CDATA[<p><!--adsense--></p>
<p><a href="http://twit88.com/blog/wp-content/uploads/2007/10/sample_plsql.sql">Download Source</a></p>
<p>Sometimes back when I was involved in a project I faced the challenge to import data from different Oracle databases synchronously within my Java web application. Performance is the key issue. The import has to be completed in a short time frame according to the SLA.</p>
<p>Of course I can dynamically create JDBC connection to the database and retrieve the data that I wanted, but it proved to be very slow.</p>
<p><span id="more-114"></span></p>
<p>Since all the databases are Oracle, I tried to use PL/SQL.  After some trials and errors, finally I create an Oracle package which can do the following</p>
<ol>
<li>Dynamically create a database link to the source database</li>
<li>Execute <strong>insert select</strong> statement in parallel to import from the source table to the target table.</li>
</ol>
<p>Since all the data import is done on the database level, and fully making use of the multiprocessor server, the performance proved to be very satisfactory.</p>
<p>Below are some of the code snippets that I used to link and unlink from the database.</p>
<blockquote><p>  function LinkDatabase(hostName varchar2,portNumber varchar2, sid varchar2,<br />
                        dbUsername varchar2, dbPassword varchar2)<br />
                        return varchar2 is</p>
<p>      dbLinkName varchar2(100);<br />
      connString varchar2(500);<br />
  begin<br />
       dbms_output.enable(1000000);<br />
       &#8212; Assign the link name<br />
       dbLinkName:=  DATABASE_LINK_PREFIX || sid;<br />
       begin<br />
            &#8212; Drop existing database link, ignoring any errors returned<br />
            execute immediate &#8216;DROP  PUBLIC DATABASE LINK &#8216; || dbLinkName;<br />
            exception<br />
                     when others then<br />
                     null;<br />
       end;<br />
       connString:= &#8216;CREATE PUBLIC  DATABASE LINK &#8216; ||<br />
                     dbLinkName ||<br />
                     &#8216; CONNECT TO &#8216; ||<br />
                     dbUserName ||<br />
                     &#8216; IDENTIFIED BY &#8216; ||<br />
                     dbPassword ||<br />
                     &#8216; USING &#8221;(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP) (HOST = &#8216; ||<br />
                     hostName ||<br />
                     &#8216;)(PORT = &#8216; ||<br />
                     portNumber ||<br />
                     &#8216;)) (CONNECT_DATA = (SID = &#8216; ||<br />
                     sid ||<br />
                     &#8216;)))&#8221;&#8217;;</p>
<p>       &#8211;dbms_output.put_line(connString);<br />
       execute immediate connString;</p>
<p>       return dbLinkName;</p>
<p>  exception<br />
       when others then<br />
            ErrHandler.log;<br />
            RAISE;<br />
  end;</p>
<p>  &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
  procedure UnLinkDatabase(linkName varchar2) is<br />
  begin<br />
       dbms_output.enable(1000000);<br />
       begin<br />
            &#8212; Drop existing database link, ignoring any errors returned<br />
            execute immediate &#8216;DROP PUBLIC DATABASE LINK &#8216; || linkName;<br />
            exception<br />
                     when others then<br />
                     null;<br />
       end;</p>
<p>  end ;</p></blockquote>
<img src="http://twit88.com/blog/?ak_action=api_record_view&id=114&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://twit88.com/blog/2007/10/02/dynamically-import-data-from-different-oracle-databases-from-web-application/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
