<?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/"
	>

<channel>
	<title>Bar Solutions WebLog</title>
	<atom:link href="http://bar-solutions.com/weblog/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://bar-solutions.com/weblog</link>
	<description>The beginning of knowledge is the discovery of something we do not understand. [Frank Herbert]</description>
	<pubDate>Fri, 30 Mar 2012 11:53:15 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.7.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>AMIS proud sponsor of the SQL Challenge</title>
		<link>http://bar-solutions.com/weblog/?p=559</link>
		<comments>http://bar-solutions.com/weblog/?p=559#comments</comments>
		<pubDate>Wed, 31 Dec 1969 19:00:00 +0000</pubDate>
		<dc:creator>Patch</dc:creator>
		
		<category><![CDATA[Oracle]]></category>

		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://bar-solutions.com/weblog/?p=559</guid>
		<description><![CDATA[
SQL today is the foundation for any successful application. Whether it is a SOA implementation, an ADF or APEX application, a Forms application or any other usage of the Oracle Database (or any other relational database), SQL is key for the success. AMIS has embraced the evolution of SQL through the subsequent releases of the [...]]]></description>
			<content:encoded><![CDATA[<p><a class="thickbox" title="PL/SQL Challenge" href="http://www.plsqlchallenge.com" rel="nofollow" target="_blank"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; margin-left: auto; border-top: 0px; margin-right: auto; border-right: 0px; padding-top: 0px" title="PLSQL Challenge" border="0" alt="PLSQL Challenge" src="http://bar-solutions.com/weblog/img/PLSQL_Challenge.png" width="446" height="89" /></a></p>
<p>SQL today is the foundation for any successful application. Whether it is a SOA implementation, an ADF or APEX application, a Forms application or any other usage of the Oracle Database (or any other relational database), SQL is key for the success. AMIS has embraced the evolution of SQL through the subsequent releases of the Oracle Database - trying to stay abreast of the latest features and adopting new functionality whenever it made pragmatic sense. In 2004 we developed the 7Up training - that introduced Oracle developers who started their Oracle careers with Oracle7 to the wonders of Oracle 9i. Through the years, this training evolved into a 7-11 training and we kept on presenting, demonstrating and writing about new ways of using SQL - through gems such as inline views and subquery factoring, analytic functions, the model clause, aggregations, multi-table DML, Flashback, intervals and many more. We must be one of the few companies in the world able to demonstrate all of the above using the DEPT and EMP tables in the SCOTT schema.</p>
<p><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: left; border-top: 0px; border-right: 0px; padding-top: 0px" title="how-to-overcome-public-speaking-300x300" border="0" alt="questions" align="left" src="http://bar-solutions.com/weblog/img/how-to-overcome-public-speaking-300x300.jpg" width="110" height="110" />In the month of April, we make another community contribution in the area of Oracle SQL: AMIS is the proud sponsor of the SQL Challenge - the world wide quiz for Oracle SQL developers that publishes weekly challenges, accessible via <a title="PL/SQL Challenge" href="http://www.plsqlchallenge.com" rel="nofollow" target="_blank">http://www.plsqlchallenge.com</a>. Various SQL-smiths at AMIS gathered to produce five challenges to be published in five consecutive weeks. Challenges ranging from beginner level questions through the advanced level questions. Demonstrating the power of SQL and the fun of playing with it. Hopefully you find a mix of both easy and mind boggling questions. Maybe there are some things you had never thought of or even heard of and can be really useful in your day-to-day work.</p>
<p><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: right; border-top: 0px; border-right: 0px; padding-top: 0px" title="Cup" border="0" alt="Cup" align="right" src="http://bar-solutions.com/weblog/img/Cup.png" width="60" height="89" />AMIS provides prizes for contestants during AMIS April at the SQL Challenge. We will be selecting 2 winners from the people who have the highest score for all the quizzes. Besides that we will also select one random winner from all the people who played at least one of the five quizzes. Prizes include your choice of a SQL related eBook and for the first place winner also a SQL related book.</p>
<p>You can expect new quizzes every Saturday for the coming 5 weeks starting March 31st.</p>
]]></content:encoded>
			<wfw:commentRss>http://bar-solutions.com/weblog/?feed=rss2&amp;p=559</wfw:commentRss>
		</item>
		<item>
		<title>What&#8217;s going on&#8230;</title>
		<link>http://bar-solutions.com/weblog/?p=556</link>
		<comments>http://bar-solutions.com/weblog/?p=556#comments</comments>
		<pubDate>Wed, 31 Dec 1969 19:00:00 +0000</pubDate>
		<dc:creator>Patch</dc:creator>
		
		<category><![CDATA[APEX]]></category>

		<category><![CDATA[Oracle]]></category>

		<category><![CDATA[PL/SQL]]></category>

		<category><![CDATA[Personal]]></category>

		<guid isPermaLink="false">http://bar-solutions.com/weblog/?p=556</guid>
		<description><![CDATA[I has been quite some time since I posted anything on my blog. That is mainly because I am busy with other things at the moment:

I will be presenting at the OGh Apex Event in Zeist (the Netherlands). I will be doing a presentation on how to build a plug-in for Apex, together with Alex [...]]]></description>
			<content:encoded><![CDATA[<p align="left">I has been quite some time since I posted anything on my blog. That is mainly because I am busy with other things at the moment:</p>
<p><span id="more-556"></span></p>
<p align="left"><a href="http://www.ogh.nl"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: left; border-top: 0px; border-right: 0px; padding-top: 0px" title="ogh" border="0" alt="ogh" align="left" src="http://bar-solutions.com/weblog/img/ogh.gif" width="86" height="80" /></a>I will be presenting at the <a title="OGH APEX DAG 26 maart 2012 FIGI Zeist" href="http://www.ogh.nl/page.aspx?event=154" rel="nofollow" target="_blank">OGh Apex Event</a> in Zeist (the Netherlands). I will be doing a presentation on how to build a plug-in for Apex, together with <a title="Notes on Oracle" href="http://nuijten.blogspot.com/" rel="nofollow" target="_blank">Alex Nuijten</a>.</p>
<p align="left">&#160;</p>
<p align="left"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: right; border-top: 0px; border-right: 0px; padding-top: 0px" title="PLSQL Challenge" border="0" alt="PLSQL Challenge" align="right" src="http://bar-solutions.com/weblog/img/PLSQL_Challenge.png" width="244" height="40" /></p>
<p align="left"><a title="AMIS" href="http://www.amis.nl" rel="nofollow" target="_blank">AMIS</a> will be sponsoring the <a title="PL/SQL Challenge" href="http://www.plsqlchallenge.com" rel="nofollow" target="_blank">SQL Challenge</a> in April. I have made a couple of questions for that. Lucas Jellema also made a couple of questions and we are now in the process of reviewing and approving them.</p>
<p align="left">I will be doing two presentations at <a title="Oracle Development Tools User Group Conference | ODTUG Kscope Conference" href="http://kscope12.com/" rel="nofollow" target="_blank">KScope12</a>.</p>
<p><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: left; border-top: 0px; border-right: 0px; padding-top: 0px" title="know-your-rights" border="0" alt="know-your-rights" align="left" src="http://bar-solutions.com/weblog/img/know-your-rights.jpg" width="244" height="190" /><a href="http://kscope12.com/component/seminar/seminarslist#Should%20Invoker%20Rights%20Be%20Used" rel="nofollow" target="_blank">Should Invoker Rights Be Used?</a> </p>
<p>When: Monday June 25, Session 3, 11:30 am - 12:30 pm </p>
<p><em>How can you ensure users use only their data and not someone else&#8217;s? How can you do this with minimal effort? How can you get rid of multiple codebases. How can you (partially) protect yourself against SQL Injection? Explore these questions and more in this informative session.</em></p>
<p>&#160;</p>
<p>&#160;</p>
<p>And</p>
<p align="left"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: right; border-top: 0px; border-right: 0px; padding-top: 0px" title="computer" border="0" alt="computer" align="right" src="http://bar-solutions.com/weblog/img/computer.jpg" width="244" height="163" /><a href="http://kscope12.com/component/seminar/seminarslist#Can%20Collections%20Speed%20Up%20Your%20PL/SQL?" rel="nofollow" target="_blank">Can Collections Speed Up Your PL/SQL?</a> </p>
<p>When: Wednesday June 27, Session 12, 8:30 am - 9:30 am </p>
<p><em>Collections (array-like structures in PL/SQL) are used in two of the most important performance features of PL/SQL: BULK COLLECT for data retrieval and FORALL for data modification. This session will cover these topics and more.</em></p>
<p>&#160;</p>
<p>And, as a cherry on the cake, I received my ACE Award yesterday</p>
<p><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="Oracle_ACE_Award" border="0" alt="Oracle_ACE_Award" src="http://bar-solutions.com/weblog/img/Oracle_ACE_Award.jpg" width="364" height="484" /></p>
]]></content:encoded>
			<wfw:commentRss>http://bar-solutions.com/weblog/?feed=rss2&amp;p=556</wfw:commentRss>
		</item>
		<item>
		<title>ACED and KScope12</title>
		<link>http://bar-solutions.com/weblog/?p=550</link>
		<comments>http://bar-solutions.com/weblog/?p=550#comments</comments>
		<pubDate>Wed, 22 Feb 2012 05:18:28 +0000</pubDate>
		<dc:creator>Patch</dc:creator>
		
		<category><![CDATA[Oracle]]></category>

		<category><![CDATA[Personal]]></category>

		<guid isPermaLink="false">http://bar-solutions.com/weblog/?p=550</guid>
		<description><![CDATA[For a couple of days my Twitter timeline is filled up (well, it&#8217;s not all that is happening) with the news that Oracle will cancel it&#8217;s support for a lot of conferences. One of them being the KScope12 conference. This is to bad, although, considering the current economic status, I can somehow understand why Oracle [...]]]></description>
			<content:encoded><![CDATA[<p align="left">For a couple of days my Twitter timeline is filled up (well, it&#8217;s not all that is happening) with the news that <a title="Oracle" href="http://www.oracle.com/" rel="nofollow" target="_blank">Oracle</a> will cancel it&#8217;s support for a lot of conferences. One of them being the <a title="Oracle Development Tools User Group Conference | ODTUG Kscope Conference" href="http://kscope12.com/" rel="nofollow" target="_blank">KScope12</a> conference. This is to bad, although, considering the current economic status, I can somehow understand why Oracle did this. I am not saying I agree, but I sort of see what they are trying to do.</p>
<p align="left">Even though this is a pretty bad thing for the conference, since a lot of ACED speakers are now cancelling their sessions, it might also be a chance for you to have your &#8216;hour of fame&#8217;. It opens a couple of slots to be filled by other people.</p>
<p align="left">Even though some of the best technologists in the world will not be appearing (you don&#8217;t get the ACED title easily) I hope (and think) this conference will be one of the best in the world.</p>
]]></content:encoded>
			<wfw:commentRss>http://bar-solutions.com/weblog/?feed=rss2&amp;p=550</wfw:commentRss>
		</item>
		<item>
		<title>Timing in PL/SQL</title>
		<link>http://bar-solutions.com/weblog/?p=546</link>
		<comments>http://bar-solutions.com/weblog/?p=546#comments</comments>
		<pubDate>Wed, 31 Dec 1969 19:00:00 +0000</pubDate>
		<dc:creator>Patch</dc:creator>
		
		<category><![CDATA[Oracle]]></category>

		<category><![CDATA[PL/SQL]]></category>

		<category><![CDATA[Tools]]></category>

		<guid isPermaLink="false">http://bar-solutions.com/weblog/?p=546</guid>
		<description><![CDATA[In my current project I wanted to add some timing to the logging the code already does. So I started my search for a good timing package. My first idea was to download PL/Vision and use the timer that is in there. Installing this was not as simple as I hoped it to be. The [...]]]></description>
			<content:encoded><![CDATA[<p align="left">In my current project I wanted to add some timing to the logging the code already does. So I started my search for a good timing package. My first idea was to download <a href="http://www.toadworld.com/Freeware/PLVisionFreeware/tabid/687/Default.aspx" title="Toad World &gt; Freeware &gt; PL/Vision Freeware" rel="nofollow" target="_blank">PL/Vision</a> and use the timer that is in there. Installing this was not as simple as I hoped it to be. The PLVTMR package relies on a couple of other packages, which in turn rely on&#8230; Not what I wanted in my current project. I was actually looking for a stand alone package which I could use. So, my search continues and brings me to <a title="oracle-developer.net" href="http://www.oracle-developer.net/" rel="nofollow" target="_blank">oracle-developer.net</a> where I found the <a title="timer.sql" href="http://www.oracle-developer.net/content/utilities/timer.sql" rel="nofollow" target="_blank">timer.sql</a> script. It was good, but not good enough.</p>
<div align="left">
<p><span id="more-546"></span></p>
</div>
<p align="left">This script was built for usage in demos and to check if different implementations differ in speed. Therefore the timer is just written to output using a procedure. I need a function to return the value of the timer so I can use the resulting value in a log message.</p>
<p align="left">I decided to take this package as a starting point and adjust it to fit my needs. That&#8217;s why I added a function to retrieve the value which would otherwise be sent to the DBMS_OUTPUT buffer. It was actually just a copy of the show procedure with just a few adjustments.</p>
<p align="left">If, like me, you want to achieve <a title="QuestTV - Steven Feuerstein&#39;s Practical Best PL/SQL - SPODify your code - aim for a Single Point of Definition" href="http://www.quest.com/tv/959824230001/Steven-Feuersteins-Practical-Best-PLSQL---SPODify-your-code---aim-for-a-Single-Point-of-Definition/Video/" rel="nofollow" target="_blank">SPOD</a> (Single Point Of Definition), then just copying bits of code just doesn&#8217;t feel right. Just looking at the code revealed that I declared the same type twice. This should be done in the declaration section of the package, so I could use it in multiple programs. I also noticed that retrieving the current timing value was done twice in exactly the same manner. This also calls for some refactoring. So I created a function that returns the timing values in a record. Hey, I can use the type I just declared globally to the package. Another great advantage of refactoring.</p>
<p align="left">After having created the function to retrieve the timing value I started using it. While using it, I found out that I actually wanted to run multiple timers at the same time. The current package only provides a single timer so I decided to add support for multiple timers. Doing so seems easy enough by using an Associative Array. But index it by a numeric value doesn&#8217;t seem like a good idea. Since <a title="Oracle" href="http://www.oracle.com/" rel="nofollow" target="_blank">Oracle</a> 9i Release 2 we can also index by VARCHAR2 which is probably a better idea than using a numeric index. Chances of using the same name for concurrently running timers are smaller than the chance of using the same number twice.</p>
<p align="left">I don&#8217;t think the code is completely done and there are certainly some pieces that can use improvement, but it works for me. If you come up with an improved version, don&#8217;t hesitate to let me (and Adrian Billington) know.</p>
<p align="left">The code for the (modified) timer package can be found <a title="timer.sql" href="http://bar-solutions.com/weblog/wp-content/timer/timer.sql" rel="nofollow" target="_blank">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://bar-solutions.com/weblog/?feed=rss2&amp;p=546</wfw:commentRss>
		</item>
		<item>
		<title>Oracle ACE</title>
		<link>http://bar-solutions.com/weblog/?p=545</link>
		<comments>http://bar-solutions.com/weblog/?p=545#comments</comments>
		<pubDate>Wed, 26 Oct 2011 08:37:47 +0000</pubDate>
		<dc:creator>Patch</dc:creator>
		
		<category><![CDATA[Oracle]]></category>

		<category><![CDATA[Personal]]></category>

		<guid isPermaLink="false">http://bar-solutions.com/weblog/?p=545</guid>
		<description><![CDATA[Just a quick note to let the world know of the fact that I am now officially an Oracle ACE. I am even in the Ace Directory. Thanks to Learco Brizzi of Itium Oracle Professionals for nominating me. And thanks to AMIS for making it possible for me to present at different conferences like KScope11 [...]]]></description>
			<content:encoded><![CDATA[<p>Just a quick note to let the world know of the fact that I am now officially an <a title="Oracle" href="http://www.oracle.com/" rel="nofollow" target="_blank">Oracle</a> ACE. I am even in the <a title="Find an Oracle ACE" href="http://apex.oracle.com/pls/otn/f?p=19297:4:999708322519043::NO:4:P4_ID:4441" rel="nofollow" target="_blank">Ace Directory</a>. Thanks to Learco Brizzi of <a title="Itium Oracle Professionals" href="http://www.itium.nl/ITIUM/" rel="nofollow" target="_blank">Itium Oracle Professionals</a> for nominating me. And thanks to <a title="AMIS" href="http://www.amis.nl" rel="nofollow" target="_blank">AMIS</a> for making it possible for me to present at different conferences like KScope11 and OPP2009.</p>
]]></content:encoded>
			<wfw:commentRss>http://bar-solutions.com/weblog/?feed=rss2&amp;p=545</wfw:commentRss>
		</item>
		<item>
		<title>Make use of exceptions</title>
		<link>http://bar-solutions.com/weblog/?p=544</link>
		<comments>http://bar-solutions.com/weblog/?p=544#comments</comments>
		<pubDate>Wed, 31 Dec 1969 19:00:00 +0000</pubDate>
		<dc:creator>Patch</dc:creator>
		
		<category><![CDATA[Oracle]]></category>

		<category><![CDATA[PL/SQL]]></category>

		<guid isPermaLink="false">http://bar-solutions.com/weblog/?p=544</guid>
		<description><![CDATA[While I was browsing the supportforum of PL/SQL Developer by Allround Automations I came across a thread about the special copy function of PL/SQL Developer. In this thread a function was written to determine if a sent in parameter (VARCHAR2) was numeric or not. I took this implementation and created my own depending on the [...]]]></description>
			<content:encoded><![CDATA[<p align="left">While I was browsing the <a title="PL/SQL Developer - Allround Automations forums" href="http://forums.allroundautomations.com/ubb/ubbthreads.php?ubb=postlist&amp;Board=3&amp;page=1" rel="nofollow" target="_blank">supportforum</a> of <a title="Allround Automations PL/SQL Developer" href="http://www.allroundautomations.com/plsqldev.html" rel="nofollow" target="_blank">PL/SQL Developer</a> by <a title="Allround Automations" href="http://www.allroundautomations.com/" rel="nofollow" target="_blank">Allround Automations</a> I came across a <a title="Spesial Copy of Procedures and functions. - Allround Automations forums" href="http://forums.allroundautomations.com/ubb/ubbthreads.php?ubb=showflat&amp;Number=42365#Post42365" rel="nofollow" target="_blank">thread</a> about the special copy function of PL/SQL Developer. In this thread a function was written to determine if a sent in parameter (VARCHAR2) was numeric or not. I took this implementation and created my own depending on the exceptions thrown by <a title="Oracle" href="http://www.oracle.com/" rel="nofollow" target="_blank">Oracle</a>.</p>
<div align="left">
<p><span id="more-544"></span></p>
</div>
<p align="left">The original code is as follows:</p>
<div class="csharpcode" align="left">
<pre class="alt"><span class="lnum">   1:  </span><span class="kwrd">CREATE</span> <span class="kwrd">OR</span> REPLACE <span class="kwrd">FUNCTION</span> is_numeric(parameter_ <span class="kwrd">IN</span> VARCHAR2) <span class="kwrd">RETURN</span> NUMBER <span class="kwrd">IS</span></pre>
</div>
<div class="csharpcode" align="left">
<pre><span class="lnum">   2:  </span>&#160;</pre>
</div>
<div class="csharpcode" align="left">
<pre class="alt"><span class="lnum">   3:  </span>  char_         VARCHAR2(1);</pre>
</div>
<div class="csharpcode" align="left">
<pre><span class="lnum">   4:  </span>  char_counter_ <span class="kwrd">INTEGER</span>;</pre>
</div>
<div class="csharpcode" align="left">
<pre class="alt"><span class="lnum">   5:  </span>  is_numeric_   NUMBER;</pre>
</div>
<div class="csharpcode" align="left">
<pre><span class="lnum">   6:  </span>&#160;</pre>
</div>
<div class="csharpcode" align="left">
<pre class="alt"><span class="lnum">   7:  </span><span class="kwrd">BEGIN</span></pre>
</div>
<div class="csharpcode" align="left">
<pre><span class="lnum">   8:  </span> </pre>
</div>
<div class="csharpcode" align="left">
<pre class="alt"><span class="lnum">   9:  </span>  is_numeric_   := 1;</pre>
</div>
<div class="csharpcode" align="left">
<pre><span class="lnum">  10:  </span>  char_counter_ := 0;</pre>
</div>
<div class="csharpcode" align="left">
<pre class="alt"><span class="lnum">  11:  </span>  <span class="kwrd">WHILE</span> (char_counter_ &lt;= length(parameter_)) LOOP</pre>
</div>
<div class="csharpcode" align="left">
<pre><span class="lnum">  12:  </span>    char_counter_ := char_counter_ + 1;</pre>
</div>
<div class="csharpcode" align="left">
<pre class="alt"><span class="lnum">  13:  </span>    char_         := substr(parameter_, char_counter_, 1);</pre>
</div>
<div class="csharpcode" align="left">
<pre><span class="lnum">  14:  </span>    <span class="kwrd">IF</span> (instr(<span class="str">'0123456789'</span>, char_, 1) = 0) <span class="kwrd">THEN</span></pre>
</div>
<div class="csharpcode" align="left">
<pre class="alt"><span class="lnum">  15:  </span>      is_numeric_ := 0;</pre>
</div>
<div class="csharpcode" align="left">
<pre><span class="lnum">  16:  </span>      <span class="kwrd">EXIT</span>;</pre>
</div>
<div class="csharpcode" align="left">
<pre class="alt"><span class="lnum">  17:  </span>    <span class="kwrd">END</span> <span class="kwrd">IF</span>;</pre>
</div>
<div class="csharpcode" align="left">
<pre><span class="lnum">  18:  </span>  <span class="kwrd">END</span> LOOP;</pre>
</div>
<div class="csharpcode" align="left">
<pre class="alt"><span class="lnum">  19:  </span> </pre>
</div>
<div class="csharpcode" align="left">
<pre><span class="lnum">  20:  </span>  <span class="kwrd">RETURN</span>(is_numeric_);</pre>
</div>
<div class="csharpcode" align="left">
<pre class="alt"><span class="lnum">  21:  </span><span class="kwrd">END</span> is_numeric;</pre>
</div>
<style type="text/css">
<p>.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<p align="left">What this code does is check every character to see if it&#8217;s a numeric character. What happens if you send in a negative number? Or if you prefix a positive number with a plus sign (+)? The current code will flag this as NOT numeric while it actually is.</p>
<p align="left">I figured I should use what is there and let Oracle do the heavy lifting. Rely on what the guys in the PL/SQL team have come up with.</p>
<p align="left">My code looks like this:</p>
<div class="csharpcode" align="left">
<pre class="alt"><span class="lnum">   1:  </span><span class="kwrd">CREATE</span> <span class="kwrd">OR</span> REPLACE <span class="kwrd">FUNCTION</span> is_numeric_pba(parameter_in <span class="kwrd">IN</span> VARCHAR2) <span class="kwrd">RETURN</span> NUMBER <span class="kwrd">IS</span></pre>
</div>
<div class="csharpcode" align="left">
<pre><span class="lnum">   2:  </span>  l_is_numeric NUMBER;</pre>
</div>
<div class="csharpcode" align="left">
<pre class="alt"><span class="lnum">   3:  </span>  l_number     NUMBER;</pre>
</div>
<div class="csharpcode" align="left">
<pre><span class="lnum">   4:  </span><span class="kwrd">BEGIN</span></pre>
</div>
<div class="csharpcode" align="left">
<pre class="alt"><span class="lnum">   5:  </span>  <span class="kwrd">BEGIN</span></pre>
</div>
<div class="csharpcode" align="left">
<pre><span class="lnum">   6:  </span>    <span class="rem">-- try to convert the parameter to a number</span></pre>
</div>
<div class="csharpcode" align="left">
<pre class="alt"><span class="lnum">   7:  </span>    l_number := to_number(parameter_in);</pre>
</div>
<div class="csharpcode" align="left">
<pre><span class="lnum">   8:  </span>    <span class="rem">-- if it works then it's a number</span></pre>
</div>
<div class="csharpcode" align="left">
<pre class="alt"><span class="lnum">   9:  </span>    l_is_numeric := 1;</pre>
</div>
<div class="csharpcode" align="left">
<pre><span class="lnum">  10:  </span>  <span class="kwrd">EXCEPTION</span></pre>
</div>
<div class="csharpcode" align="left">
<pre class="alt"><span class="lnum">  11:  </span>    <span class="kwrd">WHEN</span> OTHERS <span class="kwrd">THEN</span></pre>
</div>
<div class="csharpcode" align="left">
<pre><span class="lnum">  12:  </span>      <span class="rem">-- if it fails then it's not a number</span></pre>
</div>
<div class="csharpcode" align="left">
<pre class="alt"><span class="lnum">  13:  </span>      l_is_numeric := 0;</pre>
</div>
<div class="csharpcode" align="left">
<pre><span class="lnum">  14:  </span>  <span class="kwrd">END</span>;</pre>
</div>
<div class="csharpcode" align="left">
<pre class="alt"><span class="lnum">  15:  </span>  <span class="kwrd">RETURN</span>(l_is_numeric);</pre>
</div>
<div class="csharpcode" align="left">
<pre><span class="lnum">  16:  </span><span class="kwrd">END</span> is_numeric_pba;</pre>
</div>
<style type="text/css">
<p>.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<p align="left">This code lets Oracle try to convert the characters into a number. If it succeeds in doing so, it&#8217;s a number. If it fails, then an exception will be thrown so it is not a number. This code also works for negative numbers and signed numbers. Heck, it even works for calculations.<br />
  <br />It is even faster than the original. </p>
<p>The test code:</p>
<div class="csharpcode" align="left">
<pre class="alt"><span class="lnum">   1:  </span>clear screen</pre>
</div>
<div class="csharpcode" align="left">
<pre><span class="lnum">   2:  </span><span class="kwrd">set</span> serveroutput <span class="kwrd">on</span> <span class="kwrd">size</span> 9000000</pre>
</div>
<div class="csharpcode" align="left">
<pre class="alt"><span class="lnum">   3:  </span><span class="kwrd">set</span> timing <span class="kwrd">on</span></pre>
</div>
<div class="csharpcode" align="left">
<pre><span class="lnum">   4:  </span><span class="kwrd">declare</span></pre>
</div>
<div class="csharpcode" align="left">
<pre class="alt"><span class="lnum">   5:  </span>  l number;</pre>
</div>
<div class="csharpcode" align="left">
<pre><span class="lnum">   6:  </span><span class="kwrd">begin</span></pre>
</div>
<div class="csharpcode" align="left">
<pre class="alt"><span class="lnum">   7:  </span>  <span class="kwrd">for</span> i <span class="kwrd">in</span> 1 .. 100000 loop</pre>
</div>
<div class="csharpcode" align="left">
<pre><span class="lnum">   8:  </span>    l := (is_numeric(i));</pre>
</div>
<div class="csharpcode" align="left">
<pre class="alt"><span class="lnum">   9:  </span>  <span class="kwrd">end</span> loop;</pre>
</div>
<div class="csharpcode" align="left">
<pre><span class="lnum">  10:  </span><span class="kwrd">end</span>;</pre>
</div>
<div class="csharpcode" align="left">
<pre class="alt"><span class="lnum">  11:  </span>/</pre>
</div>
<div class="csharpcode" align="left">
<pre><span class="lnum">  12:  </span><span class="kwrd">declare</span></pre>
</div>
<div class="csharpcode" align="left">
<pre class="alt"><span class="lnum">  13:  </span>  l number;</pre>
</div>
<div class="csharpcode" align="left">
<pre><span class="lnum">  14:  </span><span class="kwrd">begin</span></pre>
</div>
<div class="csharpcode" align="left">
<pre class="alt"><span class="lnum">  15:  </span>  <span class="kwrd">for</span> i <span class="kwrd">in</span> 1 .. 100000 loop</pre>
</div>
<div class="csharpcode" align="left">
<pre><span class="lnum">  16:  </span>    l := (is_numeric_pba(i));</pre>
</div>
<div class="csharpcode" align="left">
<pre class="alt"><span class="lnum">  17:  </span>  <span class="kwrd">end</span> loop;</pre>
</div>
<div class="csharpcode" align="left">
<pre><span class="lnum">  18:  </span><span class="kwrd">end</span>;</pre>
</div>
<div class="csharpcode" align="left">
<pre class="alt"><span class="lnum">  19:  </span>/</pre>
</div>
<div class="csharpcode" align="left">
<pre><span class="lnum">  20:  </span>&#160;</pre>
</div>
<p align="left">
<style type="text/css">
<p>.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<p>Some results: </p>
<div class="csharpcode" align="left">
<pre class="alt"><span class="lnum">   1:  </span>Connected to Oracle Database 10g Enterprise Edition Release 10.2.0.4.0</pre>
</div>
<div class="csharpcode" align="left">
<pre><span class="lnum">   2:  </span>Connected</pre>
</div>
<div class="csharpcode" align="left">
<pre class="alt"><span class="lnum">   3:  </span> </pre>
</div>
<div class="csharpcode" align="left">
<pre><span class="lnum">   4:  </span>PL/SQL procedure successfully completed</pre>
</div>
<div class="csharpcode" align="left">
<pre class="alt"><span class="lnum">   5:  </span> </pre>
</div>
<div class="csharpcode" align="left">
<pre><span class="lnum">   6:  </span>Executed in 0.375 seconds</pre>
</div>
<div class="csharpcode" align="left">
<pre class="alt"><span class="lnum">   7:  </span> </pre>
</div>
<div class="csharpcode" align="left">
<pre><span class="lnum">   8:  </span>PL/SQL procedure successfully completed</pre>
</div>
<div class="csharpcode" align="left">
<pre class="alt"><span class="lnum">   9:  </span> </pre>
</div>
<div class="csharpcode" align="left">
<pre><span class="lnum">  10:  </span>Executed in 0.094 seconds</pre>
</div>
<p align="left">
<style type="text/css">
<p>.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<p>(I had to run it a lot of times to see any difference ;-)) </p>
<p>Seems that Oracle internally does a better and faster job than you can with your own code :-).</p>
]]></content:encoded>
			<wfw:commentRss>http://bar-solutions.com/weblog/?feed=rss2&amp;p=544</wfw:commentRss>
		</item>
		<item>
		<title>SQL things to remember</title>
		<link>http://bar-solutions.com/weblog/?p=535</link>
		<comments>http://bar-solutions.com/weblog/?p=535#comments</comments>
		<pubDate>Wed, 31 Dec 1969 19:00:00 +0000</pubDate>
		<dc:creator>Patch</dc:creator>
		
		<category><![CDATA[Oracle]]></category>

		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://bar-solutions.com/weblog/?p=535</guid>
		<description><![CDATA[During my work lately I found out some things about SQL (or is it Oracle SQL) that I didn&#8217;t know about and have really made my life easier. Well, maybe not easier, but at least it enriched my knowledge  



Subquery on multiple columns
I needed to query a table but the records needed to be [...]]]></description>
			<content:encoded><![CDATA[<p align="left">During my work lately I found out some things about SQL (or is it <a title="Oracle" href="http://www.oracle.com" rel="nofollow" target="_blank">Oracle</a> SQL) that I didn&#8217;t know about and have really made my life easier. Well, maybe not easier, but at least it enriched my knowledge <img src='http://bar-solutions.com/weblog/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<div align="left">
<span id="more-535"></span>
</div>
<h2 align="left">Subquery on multiple columns</h2>
<p align="left">I needed to query a table but the records needed to be available in a subquery. Normally I would write a statement like this:<br />
<font size="2" face="Courier New"></p>
<pre>
SELECT a.*
  FROM a
 WHERE a.field in (SELECT b.field
                     FROM b
                    WHERE ...)
</pre>
<p></font>
</p>
<p align="left">But in this case I needed to check 2 columns for equality. I thought, hey, no problem, I&#8217;ll just rewrite the query to use an EXISTS instead of an IN:<br />
<font size="2" face="Courier New"></p>
<pre>
SELECT a.*
  FROM a
 WHERE EXISTS (SELECT 1
                 FROM b
                WHERE b.field1 = a.field1
                  AND b.field2 = a.field2)
</pre>
<p></font>
</p>
<p align="left">That was a nice idea but when I ran this query, it didn&#8217;t return any results before I decided to kill the query (after 15 minutes).<br />
  <br />There must be a way to query a subset and compare it to multiple columns. After a quick search on the internet I learned that is was possible to use the IN set operator on multiple columns. </p>
<p><font size="2" face="Courier New"></p>
<pre>
SELECT a.*
  FROM a
 WHERE (a.field1, a.field2) IN (SELECT b.field1, b.field2
                                  FROM b)
</pre>
<p></font>
</p>
<p align="left">This query returned results within seconds.</p>
<h2 align="left">CASE as parameter</h2>
<p align="left">I have a table in which I need to replace numeric values with their successor. The field is filled like this: xxxTry where it should become xxxTryy incrementing y by 1. Ok, this may look complicated, maybe an example will explain it:<br />
  <br />010Tr7 must become 010Tr08<br />
  <br />010Tr8 must become 010Tr09<br />
  <br />010Tr9 must become 010Tr10.</p>
<p align="left">First I thought to nest a lot of replace statements like this:<br />
<font size="2" face="Courier New"></p>
<pre>
SELECT DISTINCT REPLACE(
                  REPLACE(
                    REPLACE(
                      REPLACE(
                        REPLACE(
                          REPLACE(
                            REPLACE(
                              t.column
                            ,'Tr9','Tr10')
                          ,'Tr8','Tr09')
                        ,'Tr7','Tr08')
                      ,'Tr6','Tr07')
                    ,'Tr5','Tr06')
                  ,'Tr4','Tr05')
                ,'Tr3','Tr04')
                ...
</pre>
<p></font>
</p>
<p align="left">This looked ugly (although it does exactly what was needed). So I tried to use the CASE EXPRESSION on the query like this:<br />
<font size="2" face="Courier New"></p>
<pre>
REPLACE(t.column
       ,CASE
          WHEN t.column LIKE '%Tr9' THEN 'Tr9'
          WHEN t.column LIKE '%Tr8' THEN 'Tr8'
          WHEN t.column LIKE '%Tr7' THEN 'Tr7'
          WHEN t.column LIKE '%Tr6' THEN 'Tr6'
          WHEN t.column LIKE '%Tr5' THEN 'Tr5'
          WHEN t.column LIKE '%Tr4' THEN 'Tr4'
          WHEN t.column LIKE '%Tr3' THEN 'Tr3'
          WHEN t.column LIKE '%Tr2' THEN 'Tr2'
          WHEN t.column LIKE '%Tr1' THEN 'Tr1'
        END
       ,CASE
          WHEN t.column LIKE '%Tr9' THEN 'Tr10'
          WHEN t.column LIKE '%Tr8' THEN 'Tr09'
          WHEN t.column LIKE '%Tr7' THEN 'Tr08'
          WHEN t.column LIKE '%Tr6' THEN 'Tr07'
          WHEN t.column LIKE '%Tr5' THEN 'Tr06'
          WHEN t.column LIKE '%Tr4' THEN 'Tr05'
          WHEN t.column LIKE '%Tr3' THEN 'Tr04'
          WHEN t.column LIKE '%Tr2' THEN 'Tr03'
          WHEN t.column LIKE '%Tr1' THEN 'Tr02'
        END)
</pre>
<p></font>
</p>
<p align="left">This is much more verbose and much more work to type it all in, but I think it’s nice to see that CASE EXPRESSIONS can be used as parameters in other functions. Of course, you wouldn’t expect differently, but I nice to see it works.<br />
  <br />By the way, the shortest query for this issue I came up with is a totally different approach: </p>
<p><font size="2" face="Courier New"></p>
<pre>
substr(t.naam,1,5) || trim(both from to_char(to_number(substr(t.naam,6))+1,'09'))
</pre>
<p></font>
</p>
<p align="left">(Note the trim function needed in the query. Check out <a title="Oracle Things I Got to Remember Not to Forget" href="http://nuijten.blogspot.com/" rel="nofollow" target="_blank">Alex Nuijten</a>s <a title="Quick: How long is this string?" href="http://nuijten.blogspot.com/2011/09/quick-how-long-is-this-string.html" rel="nofollow" target="_blank">blog</a> on why this is).</p>
<p align="left">Just a couple of things I learned lately.<br />
  </p>
]]></content:encoded>
			<wfw:commentRss>http://bar-solutions.com/weblog/?feed=rss2&amp;p=535</wfw:commentRss>
		</item>
		<item>
		<title>Using Table Functions</title>
		<link>http://bar-solutions.com/weblog/?p=532</link>
		<comments>http://bar-solutions.com/weblog/?p=532#comments</comments>
		<pubDate>Wed, 31 Dec 1969 19:00:00 +0000</pubDate>
		<dc:creator>Patch</dc:creator>
		
		<category><![CDATA[Oracle]]></category>

		<category><![CDATA[PL/SQL]]></category>

		<category><![CDATA[SQL]]></category>

		<category><![CDATA[Tools]]></category>

		<guid isPermaLink="false">http://bar-solutions.com/weblog/?p=532</guid>
		<description><![CDATA[Overview of table functions
Table functions are functions that produce a collection or rows (either a nested table or a varray) that can be queried like a physical database table. You use a table function like the name of a database table, in the FROM clause of a query. The difference with a physical database table [...]]]></description>
			<content:encoded><![CDATA[<h2 align="left">Overview of table functions</h2>
<p align="left">Table functions are functions that produce a collection or rows (either a nested table or a varray) that can be queried like a physical database table. You use a table function like the name of a database table, in the FROM clause of a query. The difference with a physical database table in the FROM clause of the query is that you need to use the TABLE() operator to tell the SQL engine that it should treat whatever comes out of the function as if it were a normal table.</p>
<p><span id="more-532"></span></p>
<h2 align="left">Table function concepts</h2>
<p align="left">There a couple of steps to take when you are working with table functions. Like when you are working with normal tables you have to describe the way the records of the collection are set up.</p>
<h5 align="left"><i>Define Record Type</i><i></i></h5>
<p align="left">First of all you define a record type. This is pretty much the same records are defined in a database table, only difference is that you are now defining an object type instead of a table.<img style="border-bottom: 0px; border-left: 0px; display: inline; margin-left: 0px; border-top: 0px; margin-right: 0px; border-right: 0px" title="record_type" border="0" alt="record_type" align="right" src="/weblog/wp-content/img/tablefunctions/record_type.png" width="48" height="21" /></p>
<pre><font size="2" face="Courier New">CREATE TYPE script_line AS OBJECT
&#160; (line NUMBER
&#160; ,text VARCHAR2(32767))
/</font></pre>
<p align="left">This creates a type that can hold the contents of a single record. Compare this to a record in a physical table. </p>
<h5 align="left"><i>Define Nested Table type</i><i></i></h5>
<p align="left">After the creation of the record type you define a Nested Table type using the previously created Record Type. You can also create a Varray type if you are absolutely certain that<img style="border-bottom: 0px; border-left: 0px; display: inline; margin-left: 0px; border-top: 0px; margin-right: 0px; border-right: 0px" title="nestedtable_type" border="0" alt="nestedtable_type" align="right" src="/weblog/wp-content/img/tablefunctions/nestedtable_type.png" width="48" height="48" /> you will not exceed the boundary of the varray.</p>
<pre><font size="2" face="Courier New">CREATE or replace TYPE script_lines AS
 TABLE OF script_line;
/</font></pre>
<h5 align="left"><i>Define function returning Nested Table type</i><i></i></h5>
<p align="left">After creating the types needed for our function we can define and implement the function in which we will do what we want it to do. </p>
<pre><font size="2" face="Courier New">CREATE OR REPLACE FUNCTION createinsertscriptfor(
&#160; tablename_in IN VARCHAR2
) RETURN script_lines</font></pre>
<p align="left">The complete implementation of the function can be found <a href="http://bar-solutions.com/software/download/table_function_for_insert_script.zip">here</a>.</p>
<p align="left">This function can encapsulate our knowledge of the datadictionary and the way an insert statement should be constructed. All the things we tend to forget all the time, like the quotes that are needed when working with varchar2 fields. Or doubling the quotes when they are present in the data.</p>
<p align="left">The function will return a nested table which is created and initialized in the declaration section of the function. For every record in the table there will be a row in the nested table.</p>
<h5 align="left"><i>Query function using the TABLE() operator</i><i></i></h5>
<p align="left">After having defined the types and the function we can query the function in SQL as if it were a physical table. Only thing we have to tell the SQL engine is to treat the result of the function as a fysical table, using the TABLE() operator, hence the name TABLE FUNCTION.</p>
<h5 align="left"><i>Nesting functions</i><i></i></h5>
<p align="left">Function can take the result of a query as input for (one of) their parameters. If we build multiple functions where one function can use the output of the other we can work with the results of the previous function without having to copy the entire collection from one function to another. When the functions are pipelined as well then there is a possibility to parallellize the execution of the functions.</p>
<h2 align="left">Pipelined table functions</h2>
<p align="left">Functions can be pipelined. This means the results will become available when they are produced. As soon as a result is available instead of adding it to the nested table it will be piped out of the function.</p>
<pre><font size="2" face="Courier New">CREATE OR REPLACE FUNCTION createinsertscriptfor(
&#160; tablename_in IN VARCHAR2
) RETURN script_lines PIPELINED</font></pre>
<p align="left">The keyword <b>PIPELINED</b> is added to the function. Instead of extending the nested table and adding the result to it, it will be piped out of the function using <b>PIPE ROW</b>. When we are done with the code in the function control can be returned using the <b>RETURN</b> keyword. There are some strange things here. The function is said to return a <b>NESTED TABLE</b> but in fact in returns single records, one at a time. If you consider the output of the entire function then you can see that a table of records is being returned. Therefore the function should be defined as if it returns a <b>NESTED TABLE</b>. When the function is at its end there is nothing left to return but control. That is why we have a <b>RETURN</b> without any value.</p>
<p align="left">If you query the function in SQL*Plus you will not see any difference in behavior. That is because SQL*Plus will retrieve the results and start displaying them when it has something like 15 results.</p>
<p align="left"><b>SQL&gt; show arraysize</b><b></b></p>
<p align="left"><b>arraysize 15</b><b></b></p>
<p align="left">When the arraysize is set to 1 then the results will be displayed one at a time as soon as they become available.</p>
<p align="left"><b>SQL&gt; set arraysize 1</b><b></b></p>
<h2 align="left">Parallel table functions</h2>
<p align="left">If your database permits it, that is when the database is setup to support it, then code can be executed in parallel. If the table is enabled for <b>PARALLEL</b> processing and the function is also parallel enabled then the function can be executed in parallel.</p>
<p>Normal execution is like this:</p>
<p align="left"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="normalexecution" border="0" alt="normalexecution" src="/weblog/wp-content/img/tablefunctions/normalexecution.png" width="640" height="131" /></p>
<p>The data travels from function to function all being processed in memory. If the functions and the table were parallel enabled then execution would be something like this:</p>
<p align="left"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="parallelexecution" border="0" alt="parallelexecution" src="/weblog/wp-content/img/tablefunctions/parallelexecution.png" width="640" height="131" /></p>
<p align="left">&#160;</p>
<p align="left">In both approaches every row of data will be kept in memory until the function is done with it. Enabling parallel execution can speed up processing even on a laptop computer with a single processor but with multiple coress. If we add the pipelined option to the function then the stress on memory would be less, since the next function can start when the previous is done with a row. In theory there will not be more rows kept in memory than the ones being processed at the moment.</p>
<p align="left">To enable a function for parallel execution all you have to do is add the <b>PARALLEL_ENABLE</b> clause to the functions signature:</p>
<pre>{[<b>ORDER | CLUSTER</b>] BY <i>column_list</i>}
<b>PARALLEL_ENABLE</b> ({<b>PARTITION</b> p <b>BY
</b>[ANY | (HASH | RANGE)
  <i>column_list</i>]} )</pre>
<p align="left">If you want to control how the data is parallelized then you should define one of the parameters of the function as a strongly typed ref cursor and use this parameter in the <b>PARTITION </b>p <b>BY</b> clause along with the type of partitioning (HASH or RANGE) and the columns you want the partitioning to be done by. If you are partitioning by ANY then you can also use a weak ref cursor. Partitioning is dividing the data being processed. If you don&#8217;t tell Oracle how the data should be partitioned, then it divides it evenly over all the parallel processes available. If you provide the HASH or RANGE parameter you have more control over what rows will be processed by which parallel process.</p>
<p align="left">&#160;</p>
<p align="left"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="partitioning" border="0" alt="partitioning" src="/weblog/wp-content/img/tablefunctions/partitioning.png" width="640" height="271" /></p>
<p align="left">
  </p>
<h2 align="left">Build a table function to export data</h2>
<p align="left">Using the knowledge we have about the datadictionary and our knowledge about table functions makes it possible to write code that creates a script to copy data from one scheme to another, for instance to copy settings from the development environment to the testing environment. Of course this script is something we could write during development, but experience teaches that we will always forget at least one row of data. If the table has a limited number of columns it&#8217;s really easy to create a SQL statement that would give us the script we want.</p>
<p align="left">Let&#8217;s use the allknown DEPT table as an example. Suppose we want to create a script like this:</p>
<pre><font size="2" face="Courier New">insert into DEPT( LOC, DNAME, DEPTNO)
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; values ( 'NEW YORK', 'ACCOUNTING', 10);
insert into DEPT( LOC, DNAME, DEPTNO)
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; values ( 'DALLAS', 'RESEARCH', 20);
insert into DEPT( LOC, DNAME, DEPTNO)
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; values ( 'CHICAGO', 'SALES', 30);
insert into DEPT( LOC, DNAME, DEPTNO)
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; values ( 'BOSTON', 'OPERATIONS', 40);</font></pre>
<p align="left">It is rather simple to create a SQL script that creates this script for us that will deliver us with exactly this script.</p>
<pre><font size="2" face="Courier New">SELECT 'insert into DEPT( LOC, DNAME, DEPTNO) values ( '''||
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; LOC||''', '''||
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </font><font size="2" face="Courier New">DNAME||''', '||
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </font><font size="2" face="Courier New">DEPTNO||');' line
&#160; FROM DEPT;</font></pre>
<p align="left">This is really easy for simple tables with a few columns although you still have to remember to double the quotes in your query and what happens when a varchar2 field has a quote in it.</p>
<p align="left">It would be so much easier to hide all this complexity behind a PL/SQL interface. And with table functtions we can.</p>
<p align="left">I have created a function that does just this. It is by far not complete and it can probably be improved a lot but it&#8217;s a nice thing to play with tablefunctions. You can download the code from this location[download link] but I will highlight some pieces of the code</p>
<p align="left">As described earlier I create a record type to hold a line for the insert script and a nested table to hold all the lines. The signature of the function is also given earlier.</p>
<p align="left">The code first gets all the columns for the table from the datadictionary. With this information the first part of the statement is built. Then all the rows in the table are being processed. Depending on their datatype they will be handled differently. A varchar column for instance will have some extra processing to make sure quotes are put in the script correctly. When a row is processed, an SQL statement is ready and can be added to the nested table. When every row is processed the entire table is returned.</p>
<h2 align="left">Available tools<img style="display: inline; margin-left: 0px; margin-right: 0px" align="right" src="http://www.red-gate.com/assets/images/boxes/large/data-compare-for-oracle.png" /></h2>
<p align="left">Ofcourse there are many tools available that can do pretty much the same thing. But what if you want to create a script which you can include in your deploy script so the DBA can run the install from SQL*Plus. There is for instance <a title="Data Compare for Oracle" href="http://www.red-gate.com/products/oracle-development/data-compare-for-oracle/?utm_source=bar-solutions&#038;utm_medium=article&#038;utm_content=table_functions&#038;utm_campaign=datacomparefororacle" target="_blank">Data Compare for Oracle</a> by <a title="Red Gate Software" href="http://www.red-gate.com" target="_blank">Red Gate</a>. To create a script that can be included in your deployment script it is easiest to create a dummy schema with the same tables you want to create a script for, but with no data in them. Then let the tool do it&#8217;s magic and check the script which can be saved and included in the overall script.</p>
<p align="left">The code generated by this tool is like this:</p>
<pre><font size="2" face="Courier New">DECLARE
 null_value CHAR(1) := NULL;
 statement1 CHAR(46);
BEGIN
 statement1 := 'INSERT INTO &quot;EMPTY&quot;.&quot;DEPT&quot; VALUES (:0, :1, :2)';
 EXECUTE IMMEDIATE statement1 USING 10, 'ACCOUNTING', 'NEW YORK';
 EXECUTE IMMEDIATE statement1 USING 20, 'RESEARCH', 'DALLAS';
 EXECUTE IMMEDIATE statement1 USING 30, 'SALES', 'CHICAGO';
 EXECUTE IMMEDIATE statement1 USING 40, 'OPERATIONS', 'BOSTON';
END;
/
COMMIT;</font></pre>
<p align="left">This is a completely different approach to the scipt using tablefunctions, but in the end the result is the same. Creating the script ourselves using a PL/SQL function is in my opinion more fun, but creating the script using the tool is probably faster. You can download a fully functional trial of <a href="http://www.red-gate.com/products/oracle-development/data-compare-for-oracle/?utm_source=bar-solutions&#038;utm_medium=article&#038;utm_content=table_functions&#038;utm_campaign=datacomparefororacle" target="_blank">Data Compare for Oracle</a> from the Red Gate website so you may as well give it a go and a generate some scripts for free this way to see for yourself.</p>
]]></content:encoded>
			<wfw:commentRss>http://bar-solutions.com/weblog/?feed=rss2&amp;p=532</wfw:commentRss>
		</item>
		<item>
		<title>Oracle Scheduler, the things you ought to know</title>
		<link>http://bar-solutions.com/weblog/?p=529</link>
		<comments>http://bar-solutions.com/weblog/?p=529#comments</comments>
		<pubDate>Wed, 31 Dec 1969 19:00:00 +0000</pubDate>
		<dc:creator>Patch</dc:creator>
		
		<category><![CDATA[Oracle]]></category>

		<category><![CDATA[PL/SQL]]></category>

		<guid isPermaLink="false">http://bar-solutions.com/weblog/?p=529</guid>
		<description><![CDATA[At the KScope conference in Long Beach, CA one of the most interesting sessions I attended was a session called: Five Features You Ought to Know About the Oracle Scheduler by Eddie Awad. It was a nice presentation where I actually learned stuff I didn&#8217;t know. At least not in relation to the Scheduler.

Of course, [...]]]></description>
			<content:encoded><![CDATA[<p>At the KScope conference in Long Beach, CA one of the most interesting sessions I attended was a session called: Five Features You Ought to Know About the Oracle Scheduler by <a title="Eddie Awad&#39;s Blog" href="http://awads.net/wp/" rel="nofollow" target="_blank">Eddie Awad</a>. It was a nice presentation where I actually learned stuff I didn&#8217;t know. At least not in relation to the Scheduler.</p>
<p><span id="more-529"></span></p>
<p>Of course, we are all (or almost all) acquainted with <a title="About DBMS_JOB" href="http://download.oracle.com/docs/cd/E11882_01/server.112/e17120/appendix_a001.htm" rel="nofollow" target="_blank">DBMS_JOB</a> to schedule jobs in the <a href="http://www.oracle.com" target="_blank">Oracle</a> database it had been replaced in Oracle 10.2 with the <a title="Overview of Oracle Scheduler" href="http://download.oracle.com/docs/cd/E11882_01/server.112/e17120/schedover001.htm" rel="nofollow" target="_blank">Oracle Scheduler</a>. You can use the scheduler to schedule jobs (hey, that&#8217;s pretty much what the name says), but you can do much more than that. The easiest way to schedule a job is create it and have it run at certain intervals, lets say every day or every week.</p>
<p>When you want to run you job every first day of the month, that&#8217;s harder and if you want to run it every last day of the month, that&#8217;s even harder. Using the Oracle Scheduler you can create rather complex schemes to run the job. The calendering syntax results in a set of timestamps when the job should be run. Eddie had a lot of examples in his&#160; presentation ranging from rather simple ones like:<br />
  <br /> Run every hour</p>
<p>&#160;<font size="2" face="Courier New">FREQ=HOURLY;INTERVAL=1;<br />
    <br /></font>or</p>
<p> Run every 5 minutes:</p>
<p>&#160;<font size="2" face="Courier New">FREQ=MINUTELY;INTERVAL=5;<br />
    <br /></font>to rather complex ones like:</p>
<p> Run at 10 pm daily from Monday to Friday</p>
<p>&#160;<font size="2" face="Courier New">FREQ=DAILY; BYDAY=MON,TUE,WED,THU,FRI; BYHOUR=22; BYMINUTE=0; BYSECOND=0;<br />
    <br /></font>to very complex ones like:</p>
<p> Run on the 60th, 120th and 180th day of the year</p>
<p><font size="2" face="Courier New"> FREQ=YEARLY; BYYEARDAY=60,120,180<br />
    <br /></font> Run on the last workday of every month, assuming that workday are Monday through Friday</p>
<p>&#160;<font size="2" face="Courier New">FREQ=MONTHLY; BYDAY=MON,TUE,WED,THU,FRI; BYSETPOS=-1</font></p>
<p>Building a schedule using these intervals is very powerful, but if you want multiple jobs to use the same schedule it can be a very tedious job to write the intervals every time. And what happens when the schedule changes? You need to change a lot of jobs. Not very Single Point Of Definition.<br />
  <br />Luckily Oracle provides us with the possibility to create schedules which can then in turn be used in the scheduled jobs. That way all the jobs that use the same schedule will be changed by changing the schedule once instead of changing all the jobs individually.</p>
<p>Another very powerful tool in the scheduler is the resource manager. Using this tool you can assign resources to certain jobs based on a schedule you created. For instance, you want an update job to run every hour, but during office hours you want to have it run with the lowest priority. Outside office hours I can consume as many resources as it needs.<br />
  <br />This would involve creating a schedule in which the office hours are set. Then we would create a resource plan where we can limit the resources for a certain job class. Then, after this, we can create jobs, associated with job classes and have then use less resources during office hours, i.e. when the resource plan is active. Note: resources will only be limited when usage reaches 100%.</p>
<p>Another powerful feature is the possibility to implement a <a title="Starting a Job When a File Arrives on a System" href="http://download.oracle.com/docs/cd/E14072_01/server.112/e10595/scheduse005.htm#ADMIN13285" rel="nofollow" target="_blank">file watcher</a> using the scheduler. This way you can start jobs when a file arrives on a system. This is a feature which is introduced in the version 11g Release 2. This is an example of an event based job. Other events include for instance:</p>
<table border="1" cellspacing="0" cellpadding="2" width="600">
<tbody>
<tr>
<td valign="top" width="300">Event Type</td>
<td valign="top" width="300">Description</td>
</tr>
<tr>
<td valign="top" width="300">job_broken</td>
<td valign="top" width="300">The job has been disabled and has changed to the BROKEN state because it exceeded the number of failures defined by the max_failures job attribute</td>
</tr>
<tr>
<td valign="top" width="300">job_disabled</td>
<td valign="top" width="300">The job was disabled by the Scheduler or by a call to SET_ATTRIBUTE</td>
</tr>
<tr>
<td valign="top" width="300">job_failed</td>
<td valign="top" width="300">The job failed, either by throwing an error or by abnormally terminating</td>
</tr>
</tbody>
</table>
<p>Using these event you can for instance run a job to send out an email or a text message to a DBA that something is wrong and have him/her take appropriate action.</p>
<p>You can view Eddies entire presentation at:<br />
  <br /><a href="http://www.scribd.com/doc/60199706/Five-Features-You-Ought-to-Know-About-the-Oracle-Scheduler-PPT">http://www.scribd.com/doc/60199706/Five-Features-You-Ought-to-Know-About-the-Oracle-Scheduler-PPT</a></p>
<p>You can also read the article he wrote to accompany the presentation at:<br />
  <br /><a href="http://www.scribd.com/doc/59265286/Five-Features-You-Ought-to-Know-About-the-Oracle-Scheduler">http://www.scribd.com/doc/59265286/Five-Features-You-Ought-to-Know-About-the-Oracle-Scheduler</a></p>
]]></content:encoded>
			<wfw:commentRss>http://bar-solutions.com/weblog/?feed=rss2&amp;p=529</wfw:commentRss>
		</item>
		<item>
		<title>[Book Review] jQuery Mobile by Jon Reid</title>
		<link>http://bar-solutions.com/weblog/?p=526</link>
		<comments>http://bar-solutions.com/weblog/?p=526#comments</comments>
		<pubDate>Wed, 31 Dec 1969 19:00:00 +0000</pubDate>
		<dc:creator>Patch</dc:creator>
		
		<category><![CDATA[Books]]></category>

		<category><![CDATA[O'Reilly]]></category>

		<guid isPermaLink="false">http://bar-solutions.com/weblog/?p=526</guid>
		<description><![CDATA[Although JQuery Mobile is still in it&#8217;s Beta phase (actually Alpha phase when the book was written) you can already start using it. If you don&#8217;t want to learn the language for a specific mobile device (iOS, Android, PalmOS etc.) and you want to leverage your webbuilding skills to mobile devices then jQuery Mobile is [...]]]></description>
			<content:encoded><![CDATA[<p align="left"><a title="jQuery Mobile" href="http://oreilly.com/catalog/0636920020585/" rel="nofollow" target="_blank"><img style="display: inline; margin-left: 0px; margin-right: 0px" alt="Book cover of jQuery Mobile" align="right" src="http://covers.oreilly.com/images/0636920020585/cat.gif" width="180" /></a>Although JQuery Mobile is still in it&#8217;s Beta phase (actually Alpha phase when the book was written) you can already start using it. If you don&#8217;t want to learn the language for a specific mobile device (iOS, Android, PalmOS etc.) and you want to leverage your webbuilding skills to mobile devices then <a title="jQuery Mobile" href="http://oreilly.com/catalog/0636920020585/" rel="nofollow" target="_blank">jQuery Mobile</a> is probably your best bet. You can leave the specifics for every platform to the jQuery team while you can focus on the look and feel of you application. And this book is a pretty good starting point for your first steps doing mobile development.</p>
<p><span id="more-526"></span></p>
<p align="left">The book starts with a high-level overview of jQuery Mobile. By following the examples in the first chapter, you will have built your first jQuery Mobile application when you are done with it. Luckily the example code can be downloaded so you don&#8217;t have to type all that ;-). Then paging and navigation in jQuery Mobile is covered and after that the UI elements (toolbars, buttons, form elements etc.) are covered. By the time you are done reading chapter 3, which is pretty fast, you can create you own mobile application.</p>
<p align="left">The next part of the book covers the new theme framework. How to use it and of course how to customize it. I have learned that application look and feel requires a whole different level of expertise and most of the time I just stick with the themes provided, but if you feel comfortable enough, don&#8217;t hesitate to have a go at customizing your mobile app. After this there is a lot of info on the new events jQuery Mobile creates (Tap, pinch zoom, swiping etc.) , what methods it exposes and how you can customize jQuery Mobile for your own applications.</p>
<p align="left">The final chapter shows how to build an actual mobile application. A tweeting client, built from scratch.</p>
<p align="left">The book assumes you are already familiar with the jQuery Javascript library. If you are not, then I suggest reading &quot;<a title="jQuery Pocket Reference" href="http://oreilly.com/catalog/0636920016182/" rel="nofollow" target="_blank">jQuery Pocket Reference</a>&quot; by David Flanagan, also available from O&#8217;Reilly. It also assumes familiarity with HTML markup (&#8221;<a title="Head First HTML with CSS &amp; XHTML" href="http://oreilly.com/catalog/9780596101978/" rel="nofollow" target="_blank">Head First HTML with CSS &amp; XHTML</a>&#8221; by Elisabeth Robson, Eric T Freeman and CSS 3 (&#8221;<a title="The Book of CSS3" href="http://oreilly.com/catalog/9781593272869/" rel="nofollow" target="_blank">The Book of CSS3</a>&#8221; by Peter Gasston).</p>
<p align="left">Some basic familiarity with mobile web browsers is also assumed. As it says in the book: Though jQuery Mobile aims to provide a cross-platform API, it is still necessary for a mobile web developer to understand mobile browsers and their capabilities.</p>
<p align="left">APEX 4.1 was originally supposed to include the jQuery Mobile framework, but since it is still in the beta phase when APEX is supposed to be released they choose not to include it. Ofcourse you can include the beta code yourself in your current APEX templates, but you should be aware of the fact that you can run into some issues and you shouldn&#8217;t build production applications with it. But still, you can learn a lot by playing around with the framework. And this book can definately help you gain more insight on how this framework works and how it can be used.</p>
]]></content:encoded>
			<wfw:commentRss>http://bar-solutions.com/weblog/?feed=rss2&amp;p=526</wfw:commentRss>
		</item>
	</channel>
</rss>

