<?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>MacLochlainns Weblog</title>
	<atom:link href="http://blog.mclaughlinsoftware.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.mclaughlinsoftware.com</link>
	<description>Michael McLaughlin's Technical Blog</description>
	<lastBuildDate>Wed, 25 Aug 2010 04:06:49 +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>Summer&#8217;s all but spent</title>
		<link>http://blog.mclaughlinsoftware.com/2010/08/24/summers-all-but-spent/</link>
		<comments>http://blog.mclaughlinsoftware.com/2010/08/24/summers-all-but-spent/#comments</comments>
		<pubDate>Wed, 25 Aug 2010 04:06:49 +0000</pubDate>
		<dc:creator>maclochlainn</dc:creator>
				<category><![CDATA[Printer Driver]]></category>

		<guid isPermaLink="false">http://blog.mclaughlinsoftware.com/?p=4104</guid>
		<description><![CDATA[Summer&#8217;s almost over and it time to start blogging again. It&#8217;s strange to think that Oracle OpenWorld is only a month away, and MySQL and JavaOne are all in the same event. I&#8217;m looking forward to it! As I did two years ago on my MacBook Pro, I&#8217;ll blog during the event on my iPad. [...]]]></description>
			<content:encoded><![CDATA[<p>Summer&#8217;s almost over and it time to start blogging again. It&#8217;s strange to think that Oracle OpenWorld is only a month away, and MySQL and JavaOne are all in the same event. I&#8217;m looking forward to it! As I did two years ago on my MacBook Pro, I&#8217;ll blog during the event on my iPad.</p>
<p>Anyway, I want to provide an observation about the HP LaserJet 1606dn and HP support. As a late reminder to me, always test purchased equipment within the return window. I failed in this case and <em>Murphy&#8217;s</em> law struck. I bought a DOA HP LaserJet 1606dn from Staples. I must go through the RMA process because I didn&#8217;t take it out of the box until after the 14 day return policy.</p>
<p>I thought explaining it to a store manager might allow me to return it, but I was wrong. <a href="http://www.staples.com/Staples-Easy-Button/product_606396?storeId=10001&#038;jspStoreDir=Staples&#038;cmSearchKeyword=easy+button&#038;fromUrl=home&#038;langId=-1&#038;catalogId=10051&#038;cmArea=SEARCH&#038;ddkey=StaplesSearch"><img src="http://blog.mclaughlinsoftware.com/wp-content/uploads/2010/08/s0105150_sc7-150x150.jpg" alt="" title="s0105150_sc7" width="150" height="150" class="alignright size-thumbnail wp-image-4115" /></a> Their policy is <em>ironclad</em>. It&#8217;s actually a wonderful example of why <a href="http://www.staples.com/">Staples&#8217;</a> <span style="color:red">Easy Button</span> <em><strong>ISN&#8217;T EASY</strong></em> for consumers when you fail to test the product within 14 days of purchase. Make that 13 days, so it can be returned on the 14th day.</p>
<p>Anyway, HP&#8217;s Support Chat Queue works well. It was responsive but the RMA policy leaves much to be desired in a world of identity theft. Their shipping group wants to call you at their convenience to secure a credit card for the RMA. They don&#8217;t provide you with a number that you can confirm, or a process that supports your schedule. Clearly, the cost of support is more important to HP than customer satisfaction.</p>
<p>I&#8217;ll update what happens as it all sorts out. The problem with the HP LaserJet 1606dn is that it doesn&#8217;t recognize ink in the LaserJet toner cartridge. It appears to be a sensor defect but the support staff person maintained excellent transparency, which means I&#8217;ll never know for sure if they shipped a bunch of bad units. The quickness in agreeing with the sensor failure gave me the impression that they may know something they&#8217;re not saying. Alas, we may never know for sure &#8230;</p>
<p>The moral of the story is always: buy, immediately test, and return failures to avoid RMAs. Especially, do so with <em>brick-and-mortar</em> stores like Staples, so you can walk it right back for a full refund and avoid the RMA.</p>
<p>After I dig into their Registry management, I&#8217;ll have more to say about working around HP&#8217;s approach to drivers. Their approach requires uninstalling the printer software and then re-installing it when you use DNS licenses for the printer IP address. It appears their logic is in a combination of configurations files and the Windows Registry. When I sort it out, I&#8217;ll post it and how to work around it. Oops, that&#8217;s hack it, isn&#8217;t it. <img src='http://blog.mclaughlinsoftware.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.mclaughlinsoftware.com/2010/08/24/summers-all-but-spent/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Bioinformatics Conference</title>
		<link>http://blog.mclaughlinsoftware.com/2010/08/06/bioinformatics-conference/</link>
		<comments>http://blog.mclaughlinsoftware.com/2010/08/06/bioinformatics-conference/#comments</comments>
		<pubDate>Sat, 07 Aug 2010 05:31:09 +0000</pubDate>
		<dc:creator>maclochlainn</dc:creator>
				<category><![CDATA[C]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Objective-C]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[SharePoint]]></category>

		<guid isPermaLink="false">http://blog.mclaughlinsoftware.com/?p=4088</guid>
		<description><![CDATA[This week I attended the first ACM conference on Bioinformatics and Computational Biology in Niagara Falls, NY. The next conference is in Rome next January. It was interesting to note who&#8217;s using what technology in their research. Here&#8217;s a breakdown: Databases: MySQL is the de facto winner for research. Oracle for clinical systems, mostly Oracle [...]]]></description>
			<content:encoded><![CDATA[<p>This week I attended the first <a href="http://www.acm.org/">ACM</a> conference on <a href="http://www.cse.buffalo.edu/ACM-BCB2010/">Bioinformatics and Computational Biology</a> in Niagara Falls, NY. The <a href="http://www.bioinformatics.biostec.org/">next conference</a> is in Rome next January. It was interesting to note who&#8217;s using what technology in their research.</p>
<p>Here&#8217;s a breakdown:</p>
<ul>
<li>Databases: MySQL is the <em>de facto</em> winner for research. Oracle for clinical systems, mostly Oracle 10<em>g</em> implementations. That means moving data between the two is a critical skill. Specifically, exporting data from Oracle and importing it into MySQL. Oracle was criticized for being a DBA-preserve and unfriendly to development. When I probed this trend, it seemed to point to DBAs over managing sandbox instances at companies with site licenses. Microsoft SQL Server didn&#8217;t find a lot of popularity in the research community.</li>
<li>Programming Skills: C#, C++, Objective-C and PHP were high on the list. <a href="http://en.wikipedia.org/wiki/C_Sharp_(programming_language)">C#</a> to import data into <a href="http://en.wikipedia.org/wiki/Microsoft_SharePoint">Microsoft SharePoint</a> and develop Windows SmartPhones. <a href="http://en.wikipedia.org/wiki/C%2B%2B">C++</a> to extend MySQL. <a href="http://en.wikipedia.org/wiki/Objective-c">Objective-C</a> to develop iPhone and iPad applications. <a href="http://en.wikipedia.org/wiki/Php">PHP</a> to build applications to manage studies and facilitate input, but there were a couple using Perl (not many).</li>
<li>Collaboration Tools: Microsoft SharePoint won handily. It&#8217;s made a home in the clinical and research communities.</li>
</ul>
<p>Overall, they want programmers who understand biology and chemistry. They&#8217;d like knowledge through Medical Microbiology and Introductory Biochemistry, and they want strong math and statistical knowledge in their programming staff. They like <em><a href="http://en.wikipedia.org/wiki/Scrum_(development)">Scrum development frameworks</a></em>. They seem to emphasize a <em>chief engineering team</em>, which means the developers get maximum face-time with the domain experts. The developers also have to speak and walk the talk of science to be very successful.</p>
<p>As to <a href="http://en.wikipedia.org/wiki/Niagara_falls">Niagara Falls</a>, I&#8217;m glad that I took my passport. The Canadian side is where I spent most of my extra time and money. It has the best views of the falls, the best food, and ambiance. Goat Island and the Cave of the Winds are the only two features I really liked on the U.S. side of Niagara Falls. The U.S. side is dreary unless you like gambling in the <a href="http://en.wikipedia.org/wiki/Seneca_Niagara_Casino_%26_Hotel">Seneca Niagara Casino &amp; Hotel</a>. Since I&#8217;m originally from Nevada, I never entered it to check it out. Technically, when you step on the casino property you enter the <a href="http://en.wikipedia.org/wiki/Seneca_Nation_of_New_York">Seneca Nation of New York</a>. The New York state government in Albany really needs to address the imbalance or they&#8217;ll continue to see Canada score the preponderance of tourist dollars.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.mclaughlinsoftware.com/2010/08/06/bioinformatics-conference/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL, XSLT &amp; Xalan Queries</title>
		<link>http://blog.mclaughlinsoftware.com/2010/07/09/mysql-xslt-xalan-queries/</link>
		<comments>http://blog.mclaughlinsoftware.com/2010/07/09/mysql-xslt-xalan-queries/#comments</comments>
		<pubDate>Sat, 10 Jul 2010 04:55:23 +0000</pubDate>
		<dc:creator>maclochlainn</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[xml]]></category>
		<category><![CDATA[xslt]]></category>

		<guid isPermaLink="false">http://blog.mclaughlinsoftware.com/?p=4070</guid>
		<description><![CDATA[I posted how to connect to an Oracle database from an XSLT library file back in August 2008. It&#8217;s an event driven XML approach that can support web page development. One of my students wanted to do the same thing against MySQL. He quickly saw that it was simply a matter of the switching the [...]]]></description>
			<content:encoded><![CDATA[<p>I posted <a href="http://blog.mclaughlinsoftware.com/2008/08/29/querying-oracle-directly-from-xml/">how to connect to an Oracle database from an XSLT library file</a> back in August 2008. It&#8217;s an event driven XML approach that can support web page development. One of my students wanted to do the same thing against MySQL. He quickly saw that it was simply a matter of the switching the JDBC library. He&#8217;s got the whole idea bundled on <a href="http://ubuntujourney.blogspot.com/2010/07/getting-mysql-data-into-xml-easily.html" rel="pingback">his blog here</a>.</p>
<div class="dropdownbox" style="padding-left:20px;background:#FFFFFF">
<p title="Click to see content ..." class="dropdownclick"><strong><em><span style="font-size:125%">XSLT Library File to Query MySQL Database</span></em></strong> <span>&darr;</span></p>
<p style="clear: both">
Unfold this if you&#8217;d like to see the XLST code he&#8217;s posted on his blog for MySQL. You&#8217;ll find that only line #10 (below) required a change. If you&#8217;re new to XSLT, you may find Doug Tidwell&#8217;s <a href="http://www.amazon.com/XSLT-2nd-Doug-Tidwell/dp/0596527217/ref=sr_1_1?ie=UTF8&#038;s=books&#038;qid=1278737275&#038;sr=8-1">XSLT, 2<sup>nd</sup> Edition book</a> very helpful.
</p>
<div>
<div class="panelCode680">

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:stylesheet</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span></span>
<span style="color: #009900;">  <span style="color: #000066;">xmlns:xsl</span>=<span style="color: #ff0000;">&quot;http://www.w3.org/1999/XSL/Transform&quot;</span></span>
<span style="color: #009900;">  <span style="color: #000066;">xmlns:sql</span>=<span style="color: #ff0000;">&quot;org.apache.xalan.lib.sql.XConnection&quot;</span></span>
<span style="color: #009900;">  <span style="color: #000066;">extension-element-prefixes</span>=<span style="color: #ff0000;">&quot;sql&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:output</span> <span style="color: #000066;">method</span>=<span style="color: #ff0000;">&quot;html&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:template</span> <span style="color: #000066;">match</span>=<span style="color: #ff0000;">&quot;/&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:variable</span></span>
<span style="color: #009900;">  <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;movies&quot;</span></span>
<span style="color: #009900;">  <span style="color: #000066;">select</span>=<span style="color: #ff0000;">&quot;sql:new('com.mysql.jdbc.Driver','jdbc:mysql:///storedb','student','student')&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:variable</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;streaming&quot;</span> <span style="color: #000066;">select</span>=<span style="color: #ff0000;">&quot;sql:disableStreamingMode($movies)&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:variable</span></span>
<span style="color: #009900;">  <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;queryResults&quot;</span></span>
<span style="color: #009900;">  <span style="color: #000066;">select</span>=<span style="color: #ff0000;">&quot;sql:query($movies,'SELECT i.item_title, i.item_asin, i.item_release_date FROM storedb.item i')&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;html<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;head<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>MySQL Result Set<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/title<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;/head<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;body</span> <span style="color: #000066;">style</span>=<span style="color: #ff0000;">&quot;font-family: sans-serif;&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;table</span> <span style="color: #000066;">border</span>=<span style="color: #ff0000;">&quot;1&quot;</span> <span style="color: #000066;">cellpadding</span>=<span style="color: #ff0000;">&quot;5&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;tr<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:for-each</span> <span style="color: #000066;">select</span>=<span style="color: #ff0000;">&quot;$queryResults/sql/metadata/column-header&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;th<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;xsl:value-of</span> <span style="color: #000066;">select</span>=<span style="color: #ff0000;">&quot;@column-label&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/th<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsl:for-each<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/tr<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:apply-templates</span> <span style="color: #000066;">select</span>=<span style="color: #ff0000;">&quot;$queryResults/sql/row-set/row&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/table<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/body<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/html<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:value-of</span> <span style="color: #000066;">select</span>=<span style="color: #ff0000;">&quot;sql:close($movies)&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsl:template<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:template</span> <span style="color: #000066;">match</span>=<span style="color: #ff0000;">&quot;row&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;tr<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;xsl:apply-templates</span> <span style="color: #000066;">select</span>=<span style="color: #ff0000;">&quot;col&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/tr<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsl:template<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:template</span> <span style="color: #000066;">match</span>=<span style="color: #ff0000;">&quot;col&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;td<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;xsl:value-of</span> <span style="color: #000066;">select</span>=<span style="color: #ff0000;">&quot;text()&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/td<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsl:template<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsl:stylesheet<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

</div>
</div>
</div>
<p>Hope this helps those looking for a solution.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.mclaughlinsoftware.com/2010/07/09/mysql-xslt-xalan-queries/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Oracle 11g XE Delay?</title>
		<link>http://blog.mclaughlinsoftware.com/2010/06/28/oracle-11g-xe/</link>
		<comments>http://blog.mclaughlinsoftware.com/2010/06/28/oracle-11g-xe/#comments</comments>
		<pubDate>Mon, 28 Jun 2010 19:42:30 +0000</pubDate>
		<dc:creator>maclochlainn</dc:creator>
				<category><![CDATA[Oracle]]></category>
		<category><![CDATA[Oracle APEX]]></category>
		<category><![CDATA[Oracle XE]]></category>

		<guid isPermaLink="false">http://blog.mclaughlinsoftware.com/?p=4056</guid>
		<description><![CDATA[Somebody posted a comment inquiring about the release of Oracle 11g XE. They felt it had been delayed. As far as I know, the last word on that came from Andy Mendelsohn last October, as published in this InfoWorld article. When Andy Mendelsohn originally announced Oracle 11g XE in an interview with the NY Times, [...]]]></description>
			<content:encoded><![CDATA[<p>Somebody posted a comment inquiring about the release of Oracle 11g XE. They felt it had been delayed. As far as I know, the last word on that came from Andy Mendelsohn last October, as published in this <a href="http://www.infoworld.com/d/applications/oracle-says-no-cost-11g-xpress-edition-still-least-year-away-555">InfoWorld article</a>.</p>
<p>When Andy Mendelsohn originally announced Oracle 11g XE in an interview with the <a href="http://www.nytimes.com/idg/IDG_852573C400693880002574CD000640AD.html">NY Times</a>, he clearly said it would be based on the terminal release of Oracle 11g. I also suspect it&#8217;ll include <a href="http://www.oracle.com/us/corporate/press/081370">APEX 4.0</a>, which was recently released. Maybe we&#8217;ll see the release at or near Oracle Open World 2010.</p>
<p>I don&#8217;t endorse the negative remarks in the InfoWorld article about why Oracle 11g XE isn&#8217;t released. While I have no direct knowledge of the forthcoming release, I think there&#8217;s an alternative explanation for any delay. Based on my involvement with the Oracle 10g XE release, I believe Oracle wants a <em>rock solid</em> starter version. At least, that was a major concern when they released Oracle 10g XE.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.mclaughlinsoftware.com/2010/06/28/oracle-11g-xe/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Correlated Update Statement</title>
		<link>http://blog.mclaughlinsoftware.com/2010/06/27/correlated-update-statement/</link>
		<comments>http://blog.mclaughlinsoftware.com/2010/06/27/correlated-update-statement/#comments</comments>
		<pubDate>Mon, 28 Jun 2010 04:12:49 +0000</pubDate>
		<dc:creator>maclochlainn</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[Oracle XE]]></category>
		<category><![CDATA[PSM]]></category>
		<category><![CDATA[Persistent Stored Modules]]></category>
		<category><![CDATA[pl/sql]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://blog.mclaughlinsoftware.com/?p=4048</guid>
		<description><![CDATA[My students wanted some additional examples on correlated update statements. I&#8217;ve been struggling with what the right way may be to illustrate them. Correlated subqueries are a hard concept to explain to those new to SQL. While correlated update statements seem impossibly obscure to many or inordinately complex. New SQL developers often flee to the [...]]]></description>
			<content:encoded><![CDATA[<p>My students wanted some additional examples on correlated update statements. I&#8217;ve been struggling with what the right way may be to illustrate them.</p>
<p>Correlated subqueries are a hard concept to explain to those new to SQL. While correlated update statements seem impossibly obscure to many or inordinately complex. New SQL developers often flee to the comfort of procedural programs when it comes to update statements.</p>
<p>This uses my video store data model. It&#8217;s a correlated update statement to clean up potential corrupt data. More or less something a DBA might run to ensure a business rule hasn&#8217;t been violated over time. It checks for the correct foreign key value in a table when a dependent table contains one or more than one row of data.</p>
<p><a href="http://blog.mclaughlinsoftware.com/wp-content/uploads/2010/06/CorrelatedUpdateStatementExampleMember.png"><img src="http://blog.mclaughlinsoftware.com/wp-content/uploads/2010/06/CorrelatedUpdateStatementExampleMember.png" alt="" title="Correlated Update Statement Example" border="none" width="583" height="307" class="aligncenter size-full wp-image-4049" /></a></p>
<p>The aqua-green box highlights a subquery that aggregates foreign key columns and groups the result with the foreign key value. The results from this subquery become a run-time view or derived table.  The result set is a foreign key value and a substitute string literal value for each row in the contact table. These results correlate to the update statement&#8217;s rows based on the input parameter. The input parameter is a column from each updated row. </p>
<p>A unique key (or check constraint) exists on the combination of the common_lookup_table, common_lookup_column, and common_lookup_type columns. This ensures that only one row is returned and assigned to the member_type column in the member table. The update statement naturally works in either Oracle or MySQL without any porting changes.</p>
<div class="dropdownbox" style="padding-left:20px;background:#FFFFFF">
<p title="Click to see content ..." class="dropdownclick"><strong><em><span style="font-size:125%">Correlated Update Statement</span></em></strong> <span>&darr;</span></p>
<p style="clear: both">
Expand this section to see the clear text for the foregoing image.</p>
<div>
<div style="padding-left:30px" class="panelCode650">

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
</pre></td><td class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">UPDATE</span> member m
<span style="color: #993333; font-weight: bold;">SET</span>    member_type <span style="color: #66cc66;">=</span>
 <span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">SELECT</span> common_lookup_id
  <span style="color: #993333; font-weight: bold;">FROM</span>   common_lookup
  <span style="color: #993333; font-weight: bold;">WHERE</span>  common_lookup_table <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'MEMBER'</span>
  <span style="color: #993333; font-weight: bold;">AND</span>    common_lookup_column <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'MEMBER_TYPE'</span>           
  <span style="color: #993333; font-weight: bold;">AND</span>    common_lookup_type <span style="color: #66cc66;">=</span>
          <span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">SELECT</span>  dt<span style="color: #66cc66;">.</span>member_type
           <span style="color: #993333; font-weight: bold;">FROM</span>   <span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">SELECT</span>   c<span style="color: #66cc66;">.</span>member_id
                   <span style="color: #66cc66;">,</span>        CASE
                              WHEN COUNT<span style="color: #66cc66;">&#40;</span>c<span style="color: #66cc66;">.</span>member_id<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&gt;</span> <span style="color: #cc66cc;">1</span> THEN <span style="color: #ff0000;">'GROUP'</span>
                              ELSE <span style="color: #ff0000;">'INDIVIDUAL'</span>
                            END <span style="color: #993333; font-weight: bold;">AS</span> member_type
                   <span style="color: #993333; font-weight: bold;">FROM</span>     contact c
                   <span style="color: #993333; font-weight: bold;">GROUP</span> <span style="color: #993333; font-weight: bold;">BY</span> c<span style="color: #66cc66;">.</span>member_id<span style="color: #66cc66;">&#41;</span> dt
           <span style="color: #993333; font-weight: bold;">WHERE</span>   dt<span style="color: #66cc66;">.</span>member_id <span style="color: #66cc66;">=</span> m<span style="color: #66cc66;">.</span>member_id<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;</pre></td></tr></table></div>

</div>
</div>
</div>
<p style="clear:both">
<p>While this type of solution is powerful in its own right, I thought it might be interesting to see their procedural equivalents. These correlated subqueries run for each row returned by the master query (or outermost statement). Therefore, they act like functions.</p>
<p>Procedural equivalents (or user-defined functions) simplify the update statement like so:</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">UPDATE</span> member m
<span style="color: #993333; font-weight: bold;">SET</span>    member_type <span style="color: #66cc66;">=</span> get_member_type<span style="color: #66cc66;">&#40;</span>m<span style="color: #66cc66;">.</span>member_id<span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p>If you&#8217;re interested in seeing how you would implement this solution in a user-defined function, just expand the dropdown that interest you.</p>
<div class="dropdownbox" style="padding-left:20px;background:#FFFFFF">
<p title="Click to see content ..." class="dropdownclick"><strong><em><span style="font-size:125%">Oracle User-Defined Function (UDF)</span></em></strong> <span>&darr;</span></p>
<p style="clear: both">
Expand this section to see how to map this logic to a PL/SQL schema-level function.</p>
<div>
<div style="padding-left:30px" class="panelCode650">

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
</pre></td><td class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">OR</span> <span style="color: #993333; font-weight: bold;">REPLACE</span> <span style="color: #993333; font-weight: bold;">FUNCTION</span> get_member_type
<span style="color: #66cc66;">&#40;</span>pv_member_id NUMBER<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">RETURN</span> NUMBER <span style="color: #993333; font-weight: bold;">IS</span>
&nbsp;
  <span style="color: #808080; font-style: italic;">-- Define a collection of strings.</span>
  TYPE type_options <span style="color: #993333; font-weight: bold;">IS</span> <span style="color: #993333; font-weight: bold;">TABLE</span> OF VARCHAR2<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">10</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
  <span style="color: #808080; font-style: italic;">-- Declare local variables.</span>
  lv_dependent NUMBER :<span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">1</span>;
  lv_return_id NUMBER;
&nbsp;
  <span style="color: #808080; font-style: italic;">-- Declare a local variable of the collection.</span>
  lv_member_type TYPE_OPTIONS :<span style="color: #66cc66;">=</span> type_options<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'INDIVIDUAL'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'GROUP'</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
  <span style="color: #808080; font-style: italic;">-- Define a dynamic cursor to count the number of foreign key values. </span>
  CURSOR count_contact <span style="color: #66cc66;">&#40;</span>cv_member_id NUMBER<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">IS</span>
    <span style="color: #993333; font-weight: bold;">SELECT</span> COUNT<span style="color: #66cc66;">&#40;</span>c<span style="color: #66cc66;">.</span>member_id<span style="color: #66cc66;">&#41;</span>
    <span style="color: #993333; font-weight: bold;">FROM</span>   contact c
    <span style="color: #993333; font-weight: bold;">WHERE</span>  c<span style="color: #66cc66;">.</span>member_id <span style="color: #66cc66;">=</span> cv_member_id;
&nbsp;
  <span style="color: #808080; font-style: italic;">-- Define a dynamic cursor to find a key for an individual or group member type.    </span>
  CURSOR get_lookup_id <span style="color: #66cc66;">&#40;</span>cv_type VARCHAR2<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">IS</span>
    <span style="color: #993333; font-weight: bold;">SELECT</span> common_lookup_id
    <span style="color: #993333; font-weight: bold;">FROM</span>   common_lookup
    <span style="color: #993333; font-weight: bold;">WHERE</span>  common_lookup_context <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'MEMBER'</span>
    <span style="color: #993333; font-weight: bold;">AND</span>    common_lookup_type <span style="color: #66cc66;">=</span> cv_type;
&nbsp;
BEGIN
&nbsp;
  <span style="color: #808080; font-style: italic;">-- Get the number of foreign key values for a contact.</span>
  OPEN  count_contact<span style="color: #66cc66;">&#40;</span>pv_member_id<span style="color: #66cc66;">&#41;</span>;
  FETCH count_contact
  <span style="color: #993333; font-weight: bold;">INTO</span>  lv_dependent;
  CLOSE count_contact;
&nbsp;
  <span style="color: #808080; font-style: italic;">-- Open the dynamic cursor with the required value.  </span>
  <span style="color: #993333; font-weight: bold;">IF</span> lv_dependent <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">1</span> THEN
    OPEN get_lookup_id<span style="color: #66cc66;">&#40;</span>lv_member_type<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
  ELSE
    OPEN get_lookup_id<span style="color: #66cc66;">&#40;</span>lv_member_type<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
  END <span style="color: #993333; font-weight: bold;">IF</span>;
&nbsp;
  <span style="color: #808080; font-style: italic;">-- Get the correct surrogate primary key value.</span>
  FETCH get_lookup_id
  <span style="color: #993333; font-weight: bold;">INTO</span>  lv_return_id;
  CLOSE get_lookup_id;
&nbsp;
  <span style="color: #808080; font-style: italic;">-- Return the correct primary key for use as a foreign key.</span>
  <span style="color: #993333; font-weight: bold;">RETURN</span> lv_return_id;
END;
<span style="color: #66cc66;">/</span></pre></td></tr></table></div>

</div>
</div>
</div>
<p style="clear:both">
<div class="dropdownbox" style="padding-left:20px;background:#FFFFFF">
<p title="Click to see content ..." class="dropdownclick"><strong><em><span style="font-size:125%">MySQL User-Defined Function (UDF)</span></em></strong> <span>&darr;</span></p>
<p style="clear: both">
Expand this section to see how to map this logic to a Persistent Stored Module (PSM) function.</p>
<div>
<div style="padding-left:30px" class="panelCode650">

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
</pre></td><td class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #ff0000;">'DROP FUNCTION IF EXISTS get_member_type'</span> <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #ff0000;">&quot;Statement&quot;</span>;
<span style="color: #993333; font-weight: bold;">DROP</span> <span style="color: #993333; font-weight: bold;">FUNCTION</span> <span style="color: #993333; font-weight: bold;">IF</span> <span style="color: #993333; font-weight: bold;">EXISTS</span> get_member_type;
&nbsp;
<span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #ff0000;">'DELIMITER $$'</span> <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #ff0000;">&quot;Statement&quot;</span>;
DELIMITER $$
&nbsp;
<span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #ff0000;">'CREATE FUNCTION get_member_type'</span> <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #ff0000;">&quot;Statement&quot;</span>$$
<span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">FUNCTION</span> get_member_type<span style="color: #66cc66;">&#40;</span>pv_member_id INT<span style="color: #66cc66;">&#41;</span> RETURNS INT 
BEGIN
&nbsp;
  <span style="color: #808080; font-style: italic;">/* Define three local variables. */</span>
  DECLARE lv_contact_number  INT;
  DECLARE lv_member_type     CHAR<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">30</span><span style="color: #66cc66;">&#41;</span>;
  DECLARE lv_return_value    INT;
&nbsp;
  <span style="color: #808080; font-style: italic;">/* Define a dynamic cursor to count the number of foreign key values. */</span>  
  DECLARE contact_cursor CURSOR <span style="color: #993333; font-weight: bold;">FOR</span>
    <span style="color: #993333; font-weight: bold;">SELECT</span> COUNT<span style="color: #66cc66;">&#40;</span>c<span style="color: #66cc66;">.</span>member_id<span style="color: #66cc66;">&#41;</span>
    <span style="color: #993333; font-weight: bold;">FROM</span>   contact c
    <span style="color: #993333; font-weight: bold;">WHERE</span>  c<span style="color: #66cc66;">.</span>member_id <span style="color: #66cc66;">=</span> pv_member_id;
&nbsp;
  <span style="color: #808080; font-style: italic;">/* Define a dynamic cursor to find a key for an individual or group member type. */</span>
  DECLARE common_lookup_cursor CURSOR <span style="color: #993333; font-weight: bold;">FOR</span>
    <span style="color: #993333; font-weight: bold;">SELECT</span> common_lookup_id
    <span style="color: #993333; font-weight: bold;">FROM</span>   common_lookup
    <span style="color: #993333; font-weight: bold;">WHERE</span>  common_lookup_table <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'MEMBER'</span>
    <span style="color: #993333; font-weight: bold;">AND</span>    common_lookup_column <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'MEMBER_TYPE'</span>           
    <span style="color: #993333; font-weight: bold;">AND</span>    common_lookup_type <span style="color: #66cc66;">=</span> lv_member_type;
&nbsp;
  <span style="color: #808080; font-style: italic;">/* Get the number of foreign key values for a contact. */</span>    
  OPEN  contact_cursor;
  FETCH contact_cursor
  <span style="color: #993333; font-weight: bold;">INTO</span>  lv_contact_number;
  CLOSE contact_cursor;
&nbsp;
  <span style="color: #808080; font-style: italic;">/* Assign group membership when more than one foreign key value is found; and
     assign individual membership when only one foreign key value is found. */</span>  
  <span style="color: #993333; font-weight: bold;">IF</span> lv_contact_number <span style="color: #66cc66;">&gt;</span> <span style="color: #cc66cc;">1</span> THEN
    <span style="color: #993333; font-weight: bold;">SET</span> lv_member_type <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'GROUP'</span>;
  ELSE
    <span style="color: #993333; font-weight: bold;">SET</span> lv_member_type <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'INDIVIDUAL'</span>;
  END <span style="color: #993333; font-weight: bold;">IF</span>;
&nbsp;
  <span style="color: #808080; font-style: italic;">/* Get the correct surrogate primary key value. */</span>  
  OPEN  common_lookup_cursor;
  FETCH common_lookup_cursor
  <span style="color: #993333; font-weight: bold;">INTO</span>  lv_return_value;
  CLOSE common_lookup_cursor;
&nbsp;
  <span style="color: #808080; font-style: italic;">/* Return the correct primary key for use as a foreign key. */</span>  
  <span style="color: #993333; font-weight: bold;">RETURN</span> lv_return_value;
END;
$$
&nbsp;
<span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #ff0000;">'DELIMITER $$'</span> <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #ff0000;">&quot;Statement&quot;</span>$$
DELIMITER ;</pre></td></tr></table></div>

</div>
</div>
</div>
<p style="clear:both">
<p>You can query the results of the update statement with the following.</p>
<div class="dropdownbox" style="padding-left:20px;background:#FFFFFF">
<p title="Click to see content ..." class="dropdownclick"><strong><em><span style="font-size:125%">Change Confirmation Query</span></em></strong> <span>&darr;</span></p>
<p style="clear: both">
Expand this section to see the query that lets you examine the changes. It runs in either Oracle or MySQL without any changes.</p>
<div>
<div style="padding-left:30px" class="panelCode650">

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span>   m<span style="color: #66cc66;">.</span>member_id
<span style="color: #66cc66;">,</span>        dt<span style="color: #66cc66;">.</span>quantity
<span style="color: #66cc66;">,</span>        m<span style="color: #66cc66;">.</span>member_type
<span style="color: #66cc66;">,</span>        cl<span style="color: #66cc66;">.</span>common_lookup_type
<span style="color: #993333; font-weight: bold;">FROM</span>     member m <span style="color: #993333; font-weight: bold;">JOIN</span> <span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">SELECT</span>   member_id
                        <span style="color: #66cc66;">,</span>        COUNT<span style="color: #66cc66;">&#40;</span>c<span style="color: #66cc66;">.</span>member_id<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> quantity
                        <span style="color: #993333; font-weight: bold;">FROM</span>     contact c
                        <span style="color: #993333; font-weight: bold;">GROUP</span> <span style="color: #993333; font-weight: bold;">BY</span> c<span style="color: #66cc66;">.</span>member_id<span style="color: #66cc66;">&#41;</span> dt
<span style="color: #993333; font-weight: bold;">ON</span>       m<span style="color: #66cc66;">.</span>member_id <span style="color: #66cc66;">=</span> dt<span style="color: #66cc66;">.</span>member_id <span style="color: #993333; font-weight: bold;">JOIN</span> common_lookup cl
<span style="color: #993333; font-weight: bold;">ON</span>       m<span style="color: #66cc66;">.</span>member_type <span style="color: #66cc66;">=</span> cl<span style="color: #66cc66;">.</span>common_lookup_id
<span style="color: #993333; font-weight: bold;">ORDER</span> <span style="color: #993333; font-weight: bold;">BY</span> m<span style="color: #66cc66;">.</span>member_id;</pre></td></tr></table></div>

</div>
</div>
</div>
<p style="clear:both">
<p>As always, I look forward to helping and gaining insight.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.mclaughlinsoftware.com/2010/06/27/correlated-update-statement/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Debugging MySQL Functions</title>
		<link>http://blog.mclaughlinsoftware.com/2010/06/26/debugging-mysql-function/</link>
		<comments>http://blog.mclaughlinsoftware.com/2010/06/26/debugging-mysql-function/#comments</comments>
		<pubDate>Sun, 27 Jun 2010 00:51:42 +0000</pubDate>
		<dc:creator>maclochlainn</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PSM]]></category>
		<category><![CDATA[Persistent Stored Modules]]></category>
		<category><![CDATA[pl/sql]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://blog.mclaughlinsoftware.com/?p=4031</guid>
		<description><![CDATA[Somebody, who read this post on Debugging MySQL Procedures, asked why the strategy of selecting a string literal didn&#8217;t work in a MySQL function. That&#8217;s easy, they&#8217;re not designed to support a SELECT statement, only a SELECT-INTO statement. Why? That&#8217;s the purpose of a function to perform something and return a single reply. That&#8217;s also [...]]]></description>
			<content:encoded><![CDATA[<p>Somebody, who read this post on <a href="http://blog.mclaughlinsoftware.com/2010/02/27/debugging-mysql-procedures/">Debugging MySQL Procedures</a>, asked why the strategy of <em>selecting</em> a string literal didn&#8217;t work in a MySQL function. That&#8217;s easy, they&#8217;re not designed to support a <code>SELECT</code> statement, only a <code>SELECT-INTO</code> statement.</p>
<p>Why? That&#8217;s the purpose of a function to perform something and return a single reply.</p>
<p>That&#8217;s also why a MySQL functions only support the <code>IN</code> mode of operation for formal and call parameters. When formal parameters are restricted to <em>in-mode-only</em> operations, they implement a <em>pass-by-value</em> function model. This can also be expressed from the other side of the looking glass. In that case, MySQL functions don&#8217;t support <em>pass-by-reference</em> functions that use the <code>INOUT</code> or <code>OUT</code> mode operations.</p>
<p>If you put a <code>SELECT</code> statement in a function to print internal values or comments, it raises an error. Take for example the following attempt to create the <code>debugging</code> function with an echo of output (that works in stored procedures).</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">FUNCTION</span> debugger<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> RETURNS INT
BEGIN
  <span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #ff0000;">'[Debug #1]'</span>;
  <span style="color: #993333; font-weight: bold;">RETURN</span> <span style="color: #cc66cc;">1</span>;
END;
$$</pre></td></tr></table></div>

<p>It fails to create the function because you&#8217;ve violated a key integrity rule. It also raises the following error:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">ERROR 1415 (0A000): Not allowed to return a result set from a function</pre></div></div>

<p>You have two potential solutions to this problem. The first is limited and inflexible. The second isn&#8217;t as limited or inflexible and is the recommended way to debug your functions without a tool. That&#8217;s to use a temporary table to record run-time debugging events.</p>
<div class="dropdownbox" style="padding-left:20px;background:#FFFFFF">
<p title="Click to see content ..." class="dropdownclick"><strong><em><span style="font-size:125%">Session Variable Debugging</span></em></strong> <span>&darr;</span></p>
<p style="clear: both">
Expand this section to see the steps for debugging functions with session variables.</p>
<div>
<ol start="1">
<li>Create two session level variables, like these:</li>
</ol>
<div style="padding-left:30px" class="panelCode650">

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SET</span> @counter :<span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">0</span>;
<span style="color: #993333; font-weight: bold;">SET</span> @msg :<span style="color: #66cc66;">=</span> <span style="color: #ff0000;">''</span>;</pre></td></tr></table></div>

</div>
<ol start="2">
<li>Create a function that uses the <code>SELECT-INTO</code> statement to collect and store debugging information during function execution.</li>
</ol>
<div style="padding-left:30px" class="panelCode650">

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">FUNCTION</span> debugger<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> RETURNS INT
BEGIN
  <span style="color: #993333; font-weight: bold;">SELECT</span> @counter <span style="color: #66cc66;">+</span> <span style="color: #cc66cc;">1</span> <span style="color: #993333; font-weight: bold;">INTO</span> @counter;
  <span style="color: #993333; font-weight: bold;">SELECT</span> CONCAT<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'[Debug #'</span><span style="color: #66cc66;">,</span>@counter<span style="color: #66cc66;">,</span><span style="color: #ff0000;">']'</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">INTO</span> @msg;
  <span style="color: #993333; font-weight: bold;">RETURN</span> <span style="color: #cc66cc;">1</span>;
END;
$$</pre></td></tr></table></div>

</div>
<ol start="3">
<li>Run the function and then query the session variable for results</li>
</ol>
<div style="padding-left:30px" class="panelCode650">

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span> debugger<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #993333; font-weight: bold;">SELECT</span> @msg;</pre></div></div>

</div>
<p style="padding-left:30px">You&#8217;ll see the following text:</p>
<div style="padding-left:30px" class="panelCode650">

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">+------------+
| @msg       |
+------------+
| [Debug #1] |
+------------+</pre></div></div>

</div>
<p style="clear:both">
</div>
</div>
<div class="dropdownbox" style="padding-left:20px;background:#FFFFFF">
<p title="Click to see content ..." class="dropdownclick"><strong><em><span style="font-size:125%">Temporary Table Debugging</span></em></strong> <span>&darr;</span></p>
<p style="clear: both">
Expand this section to see the steps for debugging functions with session variables.</p>
<div>
<ol start="1">
<li>Only when you want a counter, create one session level variables.</li>
</ol>
<div style="padding-left:30px" class="panelCode650">

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SET</span> @counter :<span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">0</span>;</pre></td></tr></table></div>

</div>
<ol start="2">
<li>Create an <em>in-memory</em> table to store debugging information from function execution.</li>
</ol>
<div style="padding-left:30px" class="panelCode650">

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> debugger
<span style="color: #66cc66;">&#40;</span> debug_comment CHAR<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">80</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> ENGINE<span style="color: #66cc66;">=</span>MEMORY;</pre></td></tr></table></div>

</div>
<ol start="3">
<li>Create a function that supports inserts into the <em>in-memory</em> table. Naturally, you may need to make the columns larger when your debugging results are large. I&#8217;ve found that 80 characters is generally adequate for most debugging exercises.</li>
</ol>
<div style="padding-left:30px" class="panelCode650">

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">FUNCTION</span> debugger<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> RETURNS INT
BEGIN
  <span style="color: #993333; font-weight: bold;">SELECT</span> @counter <span style="color: #66cc66;">+</span> <span style="color: #cc66cc;">1</span> <span style="color: #993333; font-weight: bold;">INTO</span> @counter;
  <span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> debugger <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span>CONCAT<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'[Debug #'</span><span style="color: #66cc66;">,</span>@counter<span style="color: #66cc66;">,</span><span style="color: #ff0000;">']'</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
  <span style="color: #993333; font-weight: bold;">RETURN</span> <span style="color: #cc66cc;">1</span>;
END;
$$</pre></td></tr></table></div>

</div>
<ol start="4">
<li>Call the function and query the debugging results.</li>
</ol>
<div style="padding-left:30px" class="panelCode650">

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span> debugger<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #993333; font-weight: bold;">SELECT</span> debugger<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #993333; font-weight: bold;">SELECT</span> debugger<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #993333; font-weight: bold;">SELECT</span> debug_comment <span style="color: #993333; font-weight: bold;">FROM</span> debugger;</pre></td></tr></table></div>

</div>
<p style="padding-left:30px">You&#8217;ll see the following text:</p>
<div style="padding-left:30px" class="panelCode650">

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">+---------------+
| debug_comment |
+---------------+
| [Debug #1]    |
| [Debug #2]    |
| [Debug #3]    |
+---------------+</pre></div></div>

</div>
<p style="clear:both">
</div>
</div>
<div class="dropdownbox" style="padding-left:20px;background:#FFFFFF">
<p title="Click to see content ..." class="dropdownclick"><strong><em><span style="font-size:125%">Complete Code Sample</span></em></strong> <span>&darr;</span></p>
<p style="clear: both">
Expand this section to see the sample working code for all examples.</p>
<div>
<p>This script creates, runs, and tests the code from the above discussions.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
</pre></td><td class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">-- Conditionally drop the function when it exists.</span>
<span style="color: #993333; font-weight: bold;">DROP</span> <span style="color: #993333; font-weight: bold;">FUNCTION</span> <span style="color: #993333; font-weight: bold;">IF</span> <span style="color: #993333; font-weight: bold;">EXISTS</span> debugger;
&nbsp;
<span style="color: #808080; font-style: italic;">-- Set delimiter to create a function with semicolon statment terminators.</span>
DELIMITER $$
&nbsp;
<span style="color: #808080; font-style: italic;">-- Create a function that returns 1.</span>
<span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">FUNCTION</span> debugger<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> RETURNS INT
BEGIN
  <span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #ff0000;">'[Debug #1]'</span>;
  <span style="color: #993333; font-weight: bold;">RETURN</span> <span style="color: #cc66cc;">1</span>;
END;
$$
&nbsp;
<span style="color: #808080; font-style: italic;">-- Reset the delimiter to enable normal execution.</span>
DELIMITER ;
&nbsp;
<span style="color: #808080; font-style: italic;">-- Declare session level variables.</span>
<span style="color: #993333; font-weight: bold;">SET</span> @counter :<span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">0</span>;
<span style="color: #993333; font-weight: bold;">SET</span> @msg :<span style="color: #66cc66;">=</span> <span style="color: #ff0000;">''</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">-- Conditionally drop the function when it exists.</span>
<span style="color: #993333; font-weight: bold;">DROP</span> <span style="color: #993333; font-weight: bold;">FUNCTION</span> <span style="color: #993333; font-weight: bold;">IF</span> <span style="color: #993333; font-weight: bold;">EXISTS</span> debugger;
&nbsp;
<span style="color: #808080; font-style: italic;">-- Set delimiter to create a function with semicolon statment terminators.</span>
DELIMITER $$
&nbsp;
<span style="color: #808080; font-style: italic;">-- Create a function that writes to local session variables.</span>
<span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">FUNCTION</span> debugger<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> RETURNS INT
BEGIN
  <span style="color: #993333; font-weight: bold;">SELECT</span> @counter <span style="color: #66cc66;">+</span> <span style="color: #cc66cc;">1</span> <span style="color: #993333; font-weight: bold;">INTO</span> @counter;
  <span style="color: #993333; font-weight: bold;">SELECT</span> CONCAT<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'[Debug #'</span><span style="color: #66cc66;">,</span>@counter<span style="color: #66cc66;">,</span><span style="color: #ff0000;">']'</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">INTO</span> @msg;
  <span style="color: #993333; font-weight: bold;">RETURN</span> <span style="color: #cc66cc;">1</span>;
END;
$$
&nbsp;
<span style="color: #808080; font-style: italic;">-- Reset the delimiter to enable normal execution.</span>
DELIMITER ;
&nbsp;
<span style="color: #808080; font-style: italic;">-- Test the function code and read the session-level variable contents.</span>
<span style="color: #993333; font-weight: bold;">SELECT</span> debugger<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #993333; font-weight: bold;">SELECT</span> @msg;
&nbsp;
<span style="color: #808080; font-style: italic;">-- Declare a session level variable.</span>
<span style="color: #993333; font-weight: bold;">SET</span> @counter :<span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">0</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">-- Conditionally drop the function when it exists.</span>
<span style="color: #993333; font-weight: bold;">DROP</span> <span style="color: #993333; font-weight: bold;">TABLE</span> <span style="color: #993333; font-weight: bold;">IF</span> <span style="color: #993333; font-weight: bold;">EXISTS</span> debugger;
&nbsp;
<span style="color: #808080; font-style: italic;">-- Create a temporary (in-memory) table to record debugging information.</span>
<span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> debugger
<span style="color: #66cc66;">&#40;</span> debug_comment CHAR<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">80</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> ENGINE<span style="color: #66cc66;">=</span>MEMORY;
&nbsp;
<span style="color: #808080; font-style: italic;">-- Conditionally drop the function when it exists.</span>
<span style="color: #993333; font-weight: bold;">DROP</span> <span style="color: #993333; font-weight: bold;">FUNCTION</span> <span style="color: #993333; font-weight: bold;">IF</span> <span style="color: #993333; font-weight: bold;">EXISTS</span> debugger;
&nbsp;
<span style="color: #808080; font-style: italic;">-- Set delimiter to create a function with semicolon statment terminators.</span>
DELIMITER $$
&nbsp;
<span style="color: #808080; font-style: italic;">-- Create a function that writes to a debugging table.</span>
<span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">FUNCTION</span> debugger<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> RETURNS INT
BEGIN
  <span style="color: #993333; font-weight: bold;">SELECT</span> @counter <span style="color: #66cc66;">+</span> <span style="color: #cc66cc;">1</span> <span style="color: #993333; font-weight: bold;">INTO</span> @counter;
  <span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> debugger <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span>CONCAT<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'[Debug #'</span><span style="color: #66cc66;">,</span>@counter<span style="color: #66cc66;">,</span><span style="color: #ff0000;">']'</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
  <span style="color: #993333; font-weight: bold;">RETURN</span> <span style="color: #cc66cc;">1</span>;
END;
$$
&nbsp;
<span style="color: #808080; font-style: italic;">-- Reset the delimiter to enable normal execution.</span>
DELIMITER ;
&nbsp;
<span style="color: #808080; font-style: italic;">-- Test the function code and read the session-level variable contents.</span>
<span style="color: #993333; font-weight: bold;">SELECT</span> debugger<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #993333; font-weight: bold;">SELECT</span> debugger<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #993333; font-weight: bold;">SELECT</span> debugger<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #993333; font-weight: bold;">SELECT</span> debug_comment <span style="color: #993333; font-weight: bold;">FROM</span> debugger;</pre></td></tr></table></div>

<p style="clear:both">
</div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://blog.mclaughlinsoftware.com/2010/06/26/debugging-mysql-function/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Show indexes in Oracle</title>
		<link>http://blog.mclaughlinsoftware.com/2010/06/22/show-indexes-in-oracle/</link>
		<comments>http://blog.mclaughlinsoftware.com/2010/06/22/show-indexes-in-oracle/#comments</comments>
		<pubDate>Tue, 22 Jun 2010 07:28:15 +0000</pubDate>
		<dc:creator>maclochlainn</dc:creator>
				<category><![CDATA[Oracle]]></category>
		<category><![CDATA[Oracle XE]]></category>
		<category><![CDATA[pl/sql]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://blog.mclaughlinsoftware.com/?p=4024</guid>
		<description><![CDATA[One of my students asked how you could show index from table_name; in Oracle. They were chagrined when I told them there wasn&#8217;t an equivalent command. Outside of using Quest&#8217;s Toad or Oracle SQL*Developer, you can query the data catalog, like so: -- SQL*Plus formatting commands. COLUMN index_name FORMAT A32 COLUMN column_position FORMAT 999 HEADING [...]]]></description>
			<content:encoded><![CDATA[<p>One of my students asked how you could <code>show index from <i>table_name</i>;</code> in Oracle. They were chagrined when I told them there wasn&#8217;t an equivalent command. Outside of using Quest&#8217;s Toad or Oracle SQL*Developer, you can query the data catalog, like so:</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">-- SQL*Plus formatting commands.</span>
<span style="color: #993333; font-weight: bold;">COLUMN</span> index_name FORMAT A32
<span style="color: #993333; font-weight: bold;">COLUMN</span> column_position FORMAT <span style="color: #cc66cc;">999</span> HEADING <span style="color: #ff0000;">&quot;COLUMN|POSITION&quot;</span>
<span style="color: #993333; font-weight: bold;">COLUMN</span> column_name FORMAT A32
&nbsp;
<span style="color: #808080; font-style: italic;">-- Ordinary query with a substitution variable.</span>
<span style="color: #993333; font-weight: bold;">SELECT</span> i<span style="color: #66cc66;">.</span>index_name
<span style="color: #66cc66;">,</span>      ic<span style="color: #66cc66;">.</span>column_position
<span style="color: #66cc66;">,</span>      ic<span style="color: #66cc66;">.</span>column_name
<span style="color: #993333; font-weight: bold;">FROM</span>   user_indexes i <span style="color: #993333; font-weight: bold;">JOIN</span> user_ind_columns ic
<span style="color: #993333; font-weight: bold;">ON</span>     i<span style="color: #66cc66;">.</span>index_name <span style="color: #66cc66;">=</span> ic<span style="color: #66cc66;">.</span>index_name
<span style="color: #993333; font-weight: bold;">WHERE</span>  i<span style="color: #66cc66;">.</span>table_name <span style="color: #66cc66;">=</span> UPPER<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'&amp;input'</span><span style="color: #66cc66;">&#41;</span></pre></div></div>

<p>Naturally, this is a subset of what&#8217;s returned by the <code>show index from <i>table_name</i></code>; syntax. There is much more information in these tables but I only wanted to show an example.</p>
<p>The <code>UPPER</code> function command ensures that the table name is found in the database. Unless you&#8217;ve created a case sensitive object, they&#8217;re stored in uppercase strings.</p>
<p>While a single SQL statement works well, a little organization in PL/SQL makes it more readable. A <code>display_indexes</code> function provides that organization. It only displays <em>normal</em> indexes, not LOB indexes, and it depends on a schema-level collection of strings. This is the user-defined type (UDT) that I used for the collection.</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">OR</span> <span style="color: #993333; font-weight: bold;">REPLACE</span> TYPE index_table <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #993333; font-weight: bold;">TABLE</span> OF VARCHAR2<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">200</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">/</span></pre></div></div>

<p>The following is the definition of the function:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
</pre></td><td class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">OR</span> <span style="color: #993333; font-weight: bold;">REPLACE</span> <span style="color: #993333; font-weight: bold;">FUNCTION</span> display_indexes
<span style="color: #66cc66;">&#40;</span> pv_table_name VARCHAR2 <span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">RETURN</span> INDEX_TABLE <span style="color: #993333; font-weight: bold;">IS</span>
&nbsp;
  <span style="color: #808080; font-style: italic;">-- Declare an iterator for the collection return variable.</span>
  index_counter  NUMBER :<span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">1</span>;
  column_counter NUMBER;
&nbsp;
  <span style="color: #808080; font-style: italic;">-- Declare and initialize local collection variable as return type.</span>
  index_desc INDEX_TABLE :<span style="color: #66cc66;">=</span> index_table<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
  <span style="color: #808080; font-style: italic;">-- Get indexes.</span>
  CURSOR index_name <span style="color: #66cc66;">&#40;</span>cv_table_name VARCHAR2<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">IS</span>
    <span style="color: #993333; font-weight: bold;">SELECT</span>   i<span style="color: #66cc66;">.</span>index_name
    <span style="color: #993333; font-weight: bold;">FROM</span>     user_indexes i
    <span style="color: #993333; font-weight: bold;">WHERE</span>    i<span style="color: #66cc66;">.</span>table_name <span style="color: #66cc66;">=</span> cv_table_name
    <span style="color: #993333; font-weight: bold;">AND</span>      i<span style="color: #66cc66;">.</span>index_type <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'NORMAL'</span>
    <span style="color: #993333; font-weight: bold;">ORDER</span> <span style="color: #993333; font-weight: bold;">BY</span> <span style="color: #cc66cc;">1</span>;
&nbsp;
  <span style="color: #808080; font-style: italic;">-- Get index columns.    </span>
  CURSOR index_columns <span style="color: #66cc66;">&#40;</span>cv_index_name VARCHAR2<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">IS</span>
    <span style="color: #993333; font-weight: bold;">SELECT</span>   ic<span style="color: #66cc66;">.</span>column_position
    <span style="color: #66cc66;">,</span>        ic<span style="color: #66cc66;">.</span>column_name
    <span style="color: #993333; font-weight: bold;">FROM</span>     user_ind_columns ic
    <span style="color: #993333; font-weight: bold;">WHERE</span>    ic<span style="color: #66cc66;">.</span>index_name <span style="color: #66cc66;">=</span> cv_index_name
    <span style="color: #993333; font-weight: bold;">ORDER</span> <span style="color: #993333; font-weight: bold;">BY</span> <span style="color: #cc66cc;">1</span>;
&nbsp;
BEGIN
&nbsp;
  <span style="color: #808080; font-style: italic;">-- Assign the table name to the collection.</span>
  index_desc<span style="color: #66cc66;">.</span>EXTEND;
  index_desc<span style="color: #66cc66;">&#40;</span>index_counter<span style="color: #66cc66;">&#41;</span> :<span style="color: #66cc66;">=</span> UPPER<span style="color: #66cc66;">&#40;</span>pv_table_name<span style="color: #66cc66;">&#41;</span>;
  index_counter :<span style="color: #66cc66;">=</span> index_counter <span style="color: #66cc66;">+</span> <span style="color: #cc66cc;">1</span>;
&nbsp;
  <span style="color: #993333; font-weight: bold;">FOR</span> i <span style="color: #993333; font-weight: bold;">IN</span> index_name<span style="color: #66cc66;">&#40;</span>UPPER<span style="color: #66cc66;">&#40;</span>pv_table_name<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> LOOP
&nbsp;
    <span style="color: #808080; font-style: italic;">-- Assign the index name to the collection.</span>
    index_desc<span style="color: #66cc66;">.</span>EXTEND;
    index_desc<span style="color: #66cc66;">&#40;</span>index_counter<span style="color: #66cc66;">&#41;</span> :<span style="color: #66cc66;">=</span> LPAD<span style="color: #66cc66;">&#40;</span>i<span style="color: #66cc66;">.</span>index_name<span style="color: #66cc66;">,</span><span style="color: #cc66cc;">2</span> <span style="color: #66cc66;">+</span> LENGTH<span style="color: #66cc66;">&#40;</span>i<span style="color: #66cc66;">.</span>index_name<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">' '</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
    <span style="color: #808080; font-style: italic;">-- Set column counter on entry to nested loop.</span>
    column_counter :<span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">1</span>;
&nbsp;
    <span style="color: #993333; font-weight: bold;">FOR</span> j <span style="color: #993333; font-weight: bold;">IN</span> index_columns<span style="color: #66cc66;">&#40;</span>i<span style="color: #66cc66;">.</span>index_name<span style="color: #66cc66;">&#41;</span> LOOP
&nbsp;
      <span style="color: #993333; font-weight: bold;">IF</span> column_counter <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">1</span> THEN
&nbsp;
        <span style="color: #808080; font-style: italic;">-- Increment the column counter, extend space, and concatenate to string.</span>
        column_counter :<span style="color: #66cc66;">=</span> column_counter <span style="color: #66cc66;">+</span> <span style="color: #cc66cc;">1</span>;
        index_desc<span style="color: #66cc66;">.</span>EXTEND;
        index_desc<span style="color: #66cc66;">&#40;</span>index_counter<span style="color: #66cc66;">&#41;</span> :<span style="color: #66cc66;">=</span> index_desc<span style="color: #66cc66;">&#40;</span>index_counter<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">||</span> <span style="color: #ff0000;">'('</span> <span style="color: #66cc66;">||</span> LOWER<span style="color: #66cc66;">&#40;</span>j<span style="color: #66cc66;">.</span>column_name<span style="color: #66cc66;">&#41;</span>;
&nbsp;
      ELSE
&nbsp;
        <span style="color: #808080; font-style: italic;">-- Add a subsequent column to the list.</span>
        index_desc<span style="color: #66cc66;">&#40;</span>index_counter<span style="color: #66cc66;">&#41;</span> :<span style="color: #66cc66;">=</span> index_desc<span style="color: #66cc66;">&#40;</span>index_counter<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">||</span> <span style="color: #ff0000;">','</span> <span style="color: #66cc66;">||</span> LOWER<span style="color: #66cc66;">&#40;</span>j<span style="color: #66cc66;">.</span>column_name<span style="color: #66cc66;">&#41;</span>;
&nbsp;
      END <span style="color: #993333; font-weight: bold;">IF</span>;
&nbsp;
    END LOOP;
&nbsp;
    <span style="color: #808080; font-style: italic;">-- Append a close parenthesis and incredment index counter.</span>
    index_desc<span style="color: #66cc66;">&#40;</span>index_counter<span style="color: #66cc66;">&#41;</span> :<span style="color: #66cc66;">=</span> index_desc<span style="color: #66cc66;">&#40;</span>index_counter<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">||</span> <span style="color: #ff0000;">')'</span>;
    index_counter :<span style="color: #66cc66;">=</span> index_counter <span style="color: #66cc66;">+</span> <span style="color: #cc66cc;">1</span>;
&nbsp;
  END LOOP;
&nbsp;
  <span style="color: #808080; font-style: italic;">-- Return the array.</span>
  <span style="color: #993333; font-weight: bold;">RETURN</span> index_desc;
END;
<span style="color: #66cc66;">/</span></pre></td></tr></table></div>

<p>You can call the function with this syntax:</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span> column_value <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #ff0000;">&quot;TRANSACTION INDEXES&quot;</span>
<span style="color: #993333; font-weight: bold;">FROM</span>   <span style="color: #993333; font-weight: bold;">TABLE</span><span style="color: #66cc66;">&#40;</span>display_indexes<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'TRANSACTION'</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p>It returns the following formatted output for the <code>TRANSACTION</code> table, which is much nicer than the SQL output. Unfortunately, it will take more effort to place it on par with the <code>show index from <i>table_name</i>;</code> in MySQL.</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">TRANSACTION INDEXES
------------------------------------------------------------------------------------------------------------------------------
TRANSACTION
  PK_TRANSACTION(transaction_id)
  UQ_TRANSACTION(rental_id,transaction_type,transaction_date,payment_method_type,payment_account_number,transaction_account)</pre></div></div>

<p>As always, I hope it helps folks.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.mclaughlinsoftware.com/2010/06/22/show-indexes-in-oracle/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL Timestamp to Date?</title>
		<link>http://blog.mclaughlinsoftware.com/2010/06/18/mysql-timestamp-to-date/</link>
		<comments>http://blog.mclaughlinsoftware.com/2010/06/18/mysql-timestamp-to-date/#comments</comments>
		<pubDate>Fri, 18 Jun 2010 23:48:00 +0000</pubDate>
		<dc:creator>maclochlainn</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://blog.mclaughlinsoftware.com/?p=4007</guid>
		<description><![CDATA[One of my ex-students asked for an example of converting a DATETIME column into a DATE data type in MySQL. He&#8217;d tried a few approaches and hadn&#8217;t been successful. It&#8217;s best to use the DATE function to convert a DATETIME to a DATE in MySQL. Create a sample TIMECLOCK table. DROP TABLE IF EXISTS timeclock; [...]]]></description>
			<content:encoded><![CDATA[<p>One of my ex-students asked for an example of converting a <code>DATETIME</code> column into a <code>DATE</code> data type in MySQL. He&#8217;d tried a few approaches and hadn&#8217;t been successful. It&#8217;s best to use the <code>DATE</code> function to convert a <code>DATETIME</code> to a <code>DATE</code> in MySQL.</p>
<ol start="1">
<li>Create a sample <code>TIMECLOCK</code> table.</li>
</ol>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">DROP</span> <span style="color: #993333; font-weight: bold;">TABLE</span> <span style="color: #993333; font-weight: bold;">IF</span> <span style="color: #993333; font-weight: bold;">EXISTS</span> timeclock;
&nbsp;
<span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> TIMECLOCK
<span style="color: #66cc66;">&#40;</span> timeclock_id  int <span style="color: #993333; font-weight: bold;">UNSIGNED</span> <span style="color: #993333; font-weight: bold;">AUTO_INCREMENT</span> <span style="color: #993333; font-weight: bold;">PRIMARY</span> <span style="color: #993333; font-weight: bold;">KEY</span>
<span style="color: #66cc66;">,</span> timein        datetime
<span style="color: #66cc66;">,</span> timeout       datetime<span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<ol start="2">
<li>Insert two rows with values in the <code>TIMEIN</code> column.</li>
</ol>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">-- Insert two rows with automatic numbering and only a &quot;time in&quot; value.</span>
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> timeclock
<span style="color: #66cc66;">&#40;</span> timein <span style="color: #66cc66;">&#41;</span>
<span style="color: #993333; font-weight: bold;">VALUES</span>
<span style="color: #66cc66;">&#40;</span>NOW<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span><span style="color: #66cc66;">&#40;</span>NOW<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<ol start="3">
<li>Update the previously inserted rows with values in the <code>TIMEOUT</code> column. The first <code>UPDATE</code> statement inserts a <em>UTC date</em> into the <code>DATETIME</code> column. That date is a time stamp of of the next day at 12:00 A.M. in the morning. The second <code>UPDATE</code> statement updates the <code>TIMEOUT</code> column with a current time stamp plus 4 hours, thirty-two minutes, and thirty-three seconds. Then, the code segment queries the results.</li>
</ol>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">-- Update with tomorrow's future date at 12:00 A.M..</span>
<span style="color: #993333; font-weight: bold;">UPDATE</span> timeclock
<span style="color: #993333; font-weight: bold;">SET</span>    timeout <span style="color: #66cc66;">=</span> ADDDATE<span style="color: #66cc66;">&#40;</span>DATE<span style="color: #66cc66;">&#40;</span>NOW<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> INTERVAL <span style="color: #cc66cc;">1</span> DAY<span style="color: #66cc66;">&#41;</span>
<span style="color: #993333; font-weight: bold;">WHERE</span>  timeclock_id <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">1</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">-- Update with a timestamp 4 hours, thirty-two minutes, and thirty-three seconds in the future.</span>
<span style="color: #993333; font-weight: bold;">UPDATE</span> timeclock
<span style="color: #993333; font-weight: bold;">SET</span>    timeout <span style="color: #66cc66;">=</span> ADDTIME<span style="color: #66cc66;">&#40;</span>NOW<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'4:32:33'</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #993333; font-weight: bold;">WHERE</span>  timeclock_id <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">2</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">-- Query the value sets.</span>
<span style="color: #993333; font-weight: bold;">SELECT</span> timein<span style="color: #66cc66;">,</span> timeout <span style="color: #993333; font-weight: bold;">FROM</span> timeclock;</pre></div></div>

<p>This returns:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">+---------------------+---------------------+
| timein              | timeout             |
+---------------------+---------------------+
| 2010-06-18 16:16:08 | 2010-06-19 00:00:00 |
| 2010-06-18 16:16:08 | 2010-06-18 20:48:42 |
+---------------------+---------------------+
2 rows in set (0.00 sec)</pre></div></div>

<ol start="4">
<li>Query the differences of the timestamps as dates and times. The <code>DATE</code> function lets you convert a <code>DATETIME</code> into a <code>DATE</code> data type. Then, the <code>DATEDIFF</code> calculates the difference and returns an integer result (the interval of days). You calculate the time difference by using the <code>TIMEDIFF</code> function.</li>
</ol>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">-- Query the difference in intervals of days.</span>
<span style="color: #993333; font-weight: bold;">SELECT</span> DATE<span style="color: #66cc66;">&#40;</span>timeout<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> dateout
<span style="color: #66cc66;">,</span>      DATE<span style="color: #66cc66;">&#40;</span>timein<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> datein
<span style="color: #66cc66;">,</span>      DATEDIFF<span style="color: #66cc66;">&#40;</span>DATE<span style="color: #66cc66;">&#40;</span>timeout<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>DATE<span style="color: #66cc66;">&#40;</span>timein<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #993333; font-weight: bold;">FROM</span> timeclock;
&nbsp;
<span style="color: #808080; font-style: italic;">-- Query the difference in intervals of time.</span>
<span style="color: #993333; font-weight: bold;">SELECT</span> timeout
<span style="color: #66cc66;">,</span>      timein
<span style="color: #66cc66;">,</span>      TIMEDIFF<span style="color: #66cc66;">&#40;</span>timeout<span style="color: #66cc66;">,</span>timein<span style="color: #66cc66;">&#41;</span>
<span style="color: #993333; font-weight: bold;">FROM</span>   timeclock;</pre></div></div>

<p>These return:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">+------------+------------+--------------------------------------+
| dateout    | datein     | DATEDIFF(DATE(timeout),DATE(timein)) |
+------------+------------+--------------------------------------+
| 2010-06-19 | 2010-06-18 |                                    1 |
| 2010-06-18 | 2010-06-18 |                                    0 |
+------------+------------+--------------------------------------+
2 rows in set (0.00 sec)
&nbsp;
+---------------------+---------------------+--------------------------+
| timeout             | timein              | TIMEDIFF(timeout,timein) |
+---------------------+---------------------+--------------------------+
| 2010-06-19 00:00:00 | 2010-06-18 16:16:08 | 07:43:52                 |
| 2010-06-18 20:48:42 | 2010-06-18 16:16:08 | 04:32:34                 |
+---------------------+---------------------+--------------------------+
2 rows in set (0.00 sec)</pre></div></div>

<p>You can also use:</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span> CAST<span style="color: #66cc66;">&#40;</span>timein <span style="color: #993333; font-weight: bold;">AS</span> DATE<span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">,</span>      CAST<span style="color: #66cc66;">&#40;</span>timeout <span style="color: #993333; font-weight: bold;">AS</span> DATE<span style="color: #66cc66;">&#41;</span>
<span style="color: #993333; font-weight: bold;">FROM</span>   timeclock;</pre></div></div>

<p>Hope this helps the one who asked how and anybody else who runs across it.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.mclaughlinsoftware.com/2010/06/18/mysql-timestamp-to-date/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>A \G Option for Oracle?</title>
		<link>http://blog.mclaughlinsoftware.com/2010/06/14/a-g-option-for-oracle/</link>
		<comments>http://blog.mclaughlinsoftware.com/2010/06/14/a-g-option-for-oracle/#comments</comments>
		<pubDate>Mon, 14 Jun 2010 07:01:04 +0000</pubDate>
		<dc:creator>maclochlainn</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[Oracle XE]]></category>
		<category><![CDATA[pl/sql]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://blog.mclaughlinsoftware.com/?p=3977</guid>
		<description><![CDATA[The \G option in MySQL lets you display rows of data as sets with the columns on the left and the data on the write. I figured it would be fun to write those for Oracle when somebody pointed out that they weren&#8217;t out there in cyberspace (first page of a Google search ). I [...]]]></description>
			<content:encoded><![CDATA[<p>The <code>\G</code> option in MySQL lets you display rows of data as sets with the columns on the left and the data on the write. I figured it would be fun to write those for Oracle when somebody pointed out that they weren&#8217;t out there in cyberspace (first page of a Google search <img src='http://blog.mclaughlinsoftware.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> ).</p>
<p>I started the program with a student&#8217;s code. I thought it a bit advanced for the student but didn&#8217;t check if he&#8217;d snagged it somewhere. Thanks to Niall Litchfield, I now know is came from an <a href="http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:1035431863958">earlier post</a> of Tom Kyte. It failed when returning a Blob, BFile, or CFile column.</p>
<p>Naturally, there are two ways to write this. One is a procedure and the other is the function. This post contains both. The procedure is limited because of potential buffer overflows associated with the <code>DBMS_OUTPUT</code> package&#8217;s display. A function isn&#8217;t limited because you can return a collection from the function.</p>
<div class="dropdownbox" style="padding-left:20px;background:#FFFFFF">
<p title="Click to see content ..." class="dropdownclick"><strong><em><span style="font-size:125%">Required setup to use the <code>DBMS_SQL</code> package</span></em></strong> <span>&darr;</span></p>
<p style="clear: both">
<p>The <code>DBMS_SQL</code> package requires permissions. There are two ways to provide those permissions. One is more secure and sensible in a production system and the other is great in a development test system.</p>
<p style="clear: both">
<div style="margin-left:20px">
<p><span sytle="font-size:115%"><strong><em>Production or Test System</em></strong></span></p>
<p>If this is a production system, you probably want to grant permissions only to the <code>SYSTEM</code> schema. This follows the practice of narrowing access to powerful features and control systems.</p>
<p>The first step requires the <code>SYS</code> user to grant permissions and authority to re-grant to individual users. You connect as the privileged user, like:</p>
<div style="code-panel650">

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;">sqlplus <span style="color: #66cc66;">/</span> <span style="color: #993333; font-weight: bold;">AS</span> sysdba</pre></div></div>

</div>
<p>When connected as the <code>SYS</code>, you run the following two commands:</p>
<div style="code-panel650">

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">GRANT</span> EXECUTE <span style="color: #993333; font-weight: bold;">ON</span> dbms_sys_sql <span style="color: #993333; font-weight: bold;">TO</span> system;
<span style="color: #993333; font-weight: bold;">GRANT</span> EXECUTE <span style="color: #993333; font-weight: bold;">ON</span> dbms_sql <span style="color: #993333; font-weight: bold;">TO</span> system;</pre></div></div>

</div>
<p>You should then define the procedure or function as a <code>CURRENT_USER</code> module. This type of module is known as an <em>invoker&#8217;s right</em> program. The code is owned by the <code>SYSTEM</code> schema but you run it on your own objects in your less privileged schema.</p>
<p>You can do that by replacing the function and procedure headers with these:</p>
<div style="code-panel650">

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">OR</span> <span style="color: #993333; font-weight: bold;">REPLACE</span> PROCEDURE display_vertical
<span style="color: #66cc66;">&#40;</span> table_name VARCHAR2<span style="color: #66cc66;">,</span> where_clause VARCHAR2 <span style="color: #66cc66;">&#41;</span> AUTHID CURRENT_USER <span style="color: #993333; font-weight: bold;">IS</span></pre></div></div>

</div>
<div style="code-panel650">

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">OR</span> <span style="color: #993333; font-weight: bold;">REPLACE</span> <span style="color: #993333; font-weight: bold;">FUNCTION</span> vertical_query
<span style="color: #66cc66;">&#40;</span> table_name VARCHAR2<span style="color: #66cc66;">,</span> where_clause VARCHAR2 <span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">RETURN</span> query_result
AUTHID CURRENT_USER <span style="color: #993333; font-weight: bold;">IS</span></pre></div></div>

</div>
<p>After you compile the procedure and function in the <code>SYSTEM</code> schema, you should grant access to a schema (more restricted) or public (as generic tools). You should also create synonyms. The following commands assume you want to deploy these as generic tools. As the <code>SYSTEM</code> user, it grants privileges and then creates public synonyms.</p>
<div style="code-panel650">

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">-- Grant privileges.</span>
<span style="color: #993333; font-weight: bold;">GRANT</span> EXECUTE <span style="color: #993333; font-weight: bold;">ON</span> display_vertical <span style="color: #993333; font-weight: bold;">TO</span> PUBLIC;
<span style="color: #993333; font-weight: bold;">GRANT</span> EXECUTE <span style="color: #993333; font-weight: bold;">ON</span> vertical_query <span style="color: #993333; font-weight: bold;">TO</span> PUBLIC;
&nbsp;
<span style="color: #808080; font-style: italic;">-- Create public synonyms.</span>
<span style="color: #993333; font-weight: bold;">CREATE</span> PUBLIC SYNONYM display_vertical <span style="color: #993333; font-weight: bold;">FOR</span> system<span style="color: #66cc66;">.</span>display_vertical;
<span style="color: #993333; font-weight: bold;">CREATE</span> PUBLIC SYNONYM vertical_query <span style="color: #993333; font-weight: bold;">FOR</span> system<span style="color: #66cc66;">.</span>vertical_query;</pre></div></div>

</div>
<p>You should now be able to call these from any schema to work with their own tables and views.</p>
<p><span sytle="font-size:115%"><strong><em>Student Development System</em></strong></span></p>
<p>If this is a test system and you&#8217;re new to Oracle, the following should help you. This shows you how to implement these in a <em>Definer&#8217;s right</em> model, inside a <code>STUDENT</code> schema.</p>
<p>This isn&#8217;t a secure design, but it allows you to keep your testing limited to a <code>STUDENT</code> schema. When these permissions aren&#8217;t granted the examples won&#8217;t work at all.</p>
<p>The first step requires the <code>SYS</code> user to grant permissions and authority to re-grant to individual users. You connect as the privileged user, like:</p>
<div style="code-panel650">

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;">sqlplus <span style="color: #66cc66;">/</span> <span style="color: #993333; font-weight: bold;">AS</span> sysdba</pre></div></div>

</div>
<p>When connected as the <code>SYS</code>, you run the following two commands:</p>
<div style="code-panel650">

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">GRANT</span> EXECUTE <span style="color: #993333; font-weight: bold;">ON</span> dbms_sys_sql <span style="color: #993333; font-weight: bold;">TO</span> system <span style="color: #993333; font-weight: bold;">WITH</span> <span style="color: #993333; font-weight: bold;">GRANT</span> <span style="color: #993333; font-weight: bold;">OPTION</span>;
<span style="color: #993333; font-weight: bold;">GRANT</span> EXECUTE <span style="color: #993333; font-weight: bold;">ON</span> dbms_sql <span style="color: #993333; font-weight: bold;">TO</span> system <span style="color: #993333; font-weight: bold;">WITH</span> <span style="color: #993333; font-weight: bold;">GRANT</span> <span style="color: #993333; font-weight: bold;">OPTION</span>;</pre></div></div>

</div>
<p>You don&#8217;t have to exit to reconnect as the <code>SYSTEM</code> user. Just type the following at the <code>SQL</code> command prompt (substitute your password <img src='http://blog.mclaughlinsoftware.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> ).</p>
<div style="code-panel650">

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;">connect system<span style="color: #66cc66;">/</span>password</pre></div></div>

</div>
<p>When connected as the <code>SYSTEM</code> user, you run the following two commands:</p>
<div style="code-panel650">

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">GRANT</span> EXECUTE <span style="color: #993333; font-weight: bold;">ON</span> dbms_sys_sql <span style="color: #993333; font-weight: bold;">TO</span> student;
<span style="color: #993333; font-weight: bold;">GRANT</span> EXECUTE <span style="color: #993333; font-weight: bold;">ON</span> dbms_sql <span style="color: #993333; font-weight: bold;">TO</span> student;</pre></div></div>

</div>
<p>You should now be able to compile the function and procedure.</p>
</div>
</div>
<div class="dropdownbox" style="padding-left:20px;background:#FFFFFF">
<p title="Click to see content ..." class="dropdownclick"><strong><em><span style="font-size:125%">Procedure for <code>\G</code> output</span></em></strong> <span>&darr;</span></p>
<p style="clear: both">
<p>The procedure nice because there&#8217;s only a dependency on the buffer size for the <code>DBMS_OUTPUT</code> package. The procedure only returns column values that are printable at the console, and it only returns the first 40 characters of long text strings.
</p>
<p style="clear: both">
<div style="margin-left:20px">
<p>Here&#8217;s the procedure definition:</p>
<div style="code-panel650">

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
</pre></td><td class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">-- Create procedure.</span>
<span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">OR</span> <span style="color: #993333; font-weight: bold;">REPLACE</span> PROCEDURE display_vertical
<span style="color: #66cc66;">&#40;</span> table_name VARCHAR2<span style="color: #66cc66;">,</span> where_clause VARCHAR2 <span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">IS</span>
&nbsp;
  <span style="color: #808080; font-style: italic;">-- Open a cursor for a query against all columns in a table. </span>
  base_stmt  INTEGER :<span style="color: #66cc66;">=</span> dbms_sql<span style="color: #66cc66;">.</span>open_cursor;
&nbsp;
  <span style="color: #808080; font-style: italic;">-- Open a cursor for a dynamically constructed query, which excludes</span>
  <span style="color: #808080; font-style: italic;">-- any non-displayable columns with text.</span>
  stmt  INTEGER :<span style="color: #66cc66;">=</span> dbms_sql<span style="color: #66cc66;">.</span>open_cursor;
&nbsp;
  <span style="color: #808080; font-style: italic;">-- Declare local variables.</span>
  colValue   VARCHAR2<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">4000</span><span style="color: #66cc66;">&#41;</span>;      <span style="color: #808080; font-style: italic;">-- Declare a maximum string length for column values.</span>
  <span style="color: #993333; font-weight: bold;">STATUS</span>     INTEGER;             <span style="color: #808080; font-style: italic;">-- Declare a variable to hold acknowledgement of DBMS_SQL.EXECUTE</span>
  tableDesc  dbms_sql<span style="color: #66cc66;">.</span>desc_tab2;  <span style="color: #808080; font-style: italic;">-- Declare a table to hold metadata for the queries.</span>
  colCount   NUMBER;              <span style="color: #808080; font-style: italic;">-- Declare a variable for the column count.</span>
  rowIndex   NUMBER :<span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">0</span>;         <span style="color: #808080; font-style: italic;">-- for displaying the row number retrieved from the cursor</span>
  colLength  NUMBER :<span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">0</span>;         <span style="color: #808080; font-style: italic;">-- for keeping track of the length of the longest column name</span>
&nbsp;
  <span style="color: #808080; font-style: italic;">-- Declare local variable for the dynamically constructed query.</span>
  dynamic_stmt VARCHAR2<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">4000</span><span style="color: #66cc66;">&#41;</span> :<span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'SELECT '</span>;
&nbsp;
  <span style="color: #808080; font-style: italic;">-- Declare an exception for a bad table name, raised by a call to</span>
  <span style="color: #808080; font-style: italic;">-- the dbms_assert.qualified_sql_name function.</span>
  table_name_error EXCEPTION;
  PRAGMA EXCEPTION_INIT<span style="color: #66cc66;">&#40;</span>table_name_error<span style="color: #66cc66;">,</span> <span style="color: #66cc66;">-</span><span style="color: #cc66cc;">942</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
  <span style="color: #808080; font-style: italic;">-- Declare exception handlers for bad WHERE clause statements.</span>
&nbsp;
  <span style="color: #808080; font-style: italic;">-- Declare an exception for a missing WHERE keyword.</span>
  missing_keyword EXCEPTION;
  PRAGMA EXCEPTION_INIT<span style="color: #66cc66;">&#40;</span>missing_keyword<span style="color: #66cc66;">,</span> <span style="color: #66cc66;">-</span><span style="color: #cc66cc;">933</span><span style="color: #66cc66;">&#41;</span>;  
&nbsp;
  <span style="color: #808080; font-style: italic;">-- Declare an exception for a bad relational operator.</span>
  invalid_relational_operator EXCEPTION;
  PRAGMA EXCEPTION_INIT<span style="color: #66cc66;">&#40;</span>invalid_relational_operator<span style="color: #66cc66;">,</span> <span style="color: #66cc66;">-</span><span style="color: #cc66cc;">920</span><span style="color: #66cc66;">&#41;</span>;  
&nbsp;
  <span style="color: #808080; font-style: italic;">-- Declare an exception for a bad column name.</span>
  invalid_identifier EXCEPTION;
  PRAGMA EXCEPTION_INIT<span style="color: #66cc66;">&#40;</span>invalid_identifier<span style="color: #66cc66;">,</span> <span style="color: #66cc66;">-</span><span style="color: #cc66cc;">904</span><span style="color: #66cc66;">&#41;</span>;  
&nbsp;
  <span style="color: #808080; font-style: italic;">-- Declare an exception for a missing backquoted apostrophe.</span>
  misquoted_string EXCEPTION;
  PRAGMA EXCEPTION_INIT<span style="color: #66cc66;">&#40;</span>misquoted_string<span style="color: #66cc66;">,</span> <span style="color: #66cc66;">-</span><span style="color: #cc66cc;">1756</span><span style="color: #66cc66;">&#41;</span>;  
&nbsp;
  <span style="color: #808080; font-style: italic;">-- Declare a function that replaces non-displayable values with text messages.</span>
  <span style="color: #993333; font-weight: bold;">FUNCTION</span> check_column<span style="color: #66cc66;">&#40;</span> p_name   VARCHAR2
                       <span style="color: #66cc66;">,</span> p_type   NUMBER <span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">RETURN</span> VARCHAR2 <span style="color: #993333; font-weight: bold;">IS</span>
&nbsp;
    <span style="color: #808080; font-style: italic;">-- Return column name or literal value.</span>
    retval VARCHAR2<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">30</span><span style="color: #66cc66;">&#41;</span>;			   
&nbsp;
  BEGIN
&nbsp;
    <span style="color: #808080; font-style: italic;">-- Find strings, numbers, dates, timestamps, rowids and replace non-display values.</span>
    <span style="color: #993333; font-weight: bold;">IF</span> p_type <span style="color: #993333; font-weight: bold;">IN</span> <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">2</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">8</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">9</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">12</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">69</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">96</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">100</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">101</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">112</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">178</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">179</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">180</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">181</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">231</span><span style="color: #66cc66;">&#41;</span> THEN
&nbsp;
      <span style="color: #808080; font-style: italic;">-- Assign the column name for a displayable column value.</span>
      retval :<span style="color: #66cc66;">=</span> p_name;
&nbsp;
    ELSE
&nbsp;
      <span style="color: #808080; font-style: italic;">-- Re-assign string literals for column names where values aren't displayable.      </span>
      <span style="color: #993333; font-weight: bold;">SELECT</span> DECODE<span style="color: #66cc66;">&#40;</span>p_type<span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">23</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">''</span><span style="color: #ff0000;">'RAW not displayable.'</span><span style="color: #ff0000;">''</span>
                          <span style="color: #66cc66;">,</span><span style="color: #cc66cc;">105</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">''</span><span style="color: #ff0000;">'MLSLABEL not displayable.'</span><span style="color: #ff0000;">''</span>
                          <span style="color: #66cc66;">,</span><span style="color: #cc66cc;">106</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">''</span><span style="color: #ff0000;">'MLSLABEL not displayable.'</span><span style="color: #ff0000;">''</span>
                          <span style="color: #66cc66;">,</span><span style="color: #cc66cc;">113</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">''</span><span style="color: #ff0000;">'BLOB not displayable.'</span><span style="color: #ff0000;">''</span>
                          <span style="color: #66cc66;">,</span><span style="color: #cc66cc;">114</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">''</span><span style="color: #ff0000;">'BFILE not displayable.'</span><span style="color: #ff0000;">''</span>
                          <span style="color: #66cc66;">,</span><span style="color: #cc66cc;">115</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">''</span><span style="color: #ff0000;">'CFILE not displayable.'</span><span style="color: #ff0000;">''</span>
                          <span style="color: #66cc66;">,</span><span style="color: #ff0000;">''</span><span style="color: #ff0000;">'UNDEFINED not displayable.'</span><span style="color: #ff0000;">''</span><span style="color: #66cc66;">&#41;</span>
      <span style="color: #993333; font-weight: bold;">INTO</span> retval
      <span style="color: #993333; font-weight: bold;">FROM</span> dual;
&nbsp;
    END <span style="color: #993333; font-weight: bold;">IF</span>;
&nbsp;
    <span style="color: #808080; font-style: italic;">-- Return the column name or a apostrophe delimited string literal.</span>
    <span style="color: #993333; font-weight: bold;">RETURN</span> retval;
  END check_column;
&nbsp;
BEGIN
&nbsp;
  <span style="color: #808080; font-style: italic;">-- Prepare unfiltered display cursor.</span>
  dbms_sql<span style="color: #66cc66;">.</span>parse<span style="color: #66cc66;">&#40;</span>base_stmt<span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'SELECT * FROM '</span> <span style="color: #66cc66;">||</span> dbms_assert<span style="color: #66cc66;">.</span>simple_sql_name<span style="color: #66cc66;">&#40;</span>table_name<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">||</span> <span style="color: #ff0000;">' '</span> <span style="color: #66cc66;">||</span> where_clause<span style="color: #66cc66;">,</span> dbms_sql<span style="color: #66cc66;">.</span>native<span style="color: #66cc66;">&#41;</span>;
&nbsp;
  <span style="color: #808080; font-style: italic;">-- Describe the table structure:</span>
  <span style="color: #808080; font-style: italic;">-- --------------------------------------------------------</span>
  <span style="color: #808080; font-style: italic;">--  1. Store metadata in tableDesc</span>
  <span style="color: #808080; font-style: italic;">--  2. Store the number of columns in colCount</span>
  <span style="color: #808080; font-style: italic;">-- --------------------------------------------------------</span>
  dbms_sql<span style="color: #66cc66;">.</span>describe_columns2<span style="color: #66cc66;">&#40;</span>base_stmt<span style="color: #66cc66;">,</span> colCount<span style="color: #66cc66;">,</span> tableDesc<span style="color: #66cc66;">&#41;</span>;
&nbsp;
  <span style="color: #808080; font-style: italic;">-- Define individual columns and assign value to colValue variable.</span>
  <span style="color: #993333; font-weight: bold;">FOR</span> i <span style="color: #993333; font-weight: bold;">IN</span> 1<span style="color: #66cc66;">..</span>colCount LOOP
&nbsp;
    <span style="color: #808080; font-style: italic;">-- Define columns for each column returned into tableDesc.</span>
    dbms_sql<span style="color: #66cc66;">.</span>define_column<span style="color: #66cc66;">&#40;</span>base_stmt<span style="color: #66cc66;">,</span> i<span style="color: #66cc66;">,</span> colValue<span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">4000</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
    <span style="color: #808080; font-style: italic;">-- Find the length of the longest column name.</span>
    <span style="color: #993333; font-weight: bold;">IF</span> LENGTH<span style="color: #66cc66;">&#40;</span>tableDesc<span style="color: #66cc66;">&#40;</span>i<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>col_name<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&gt;</span> colLength THEN
      colLength :<span style="color: #66cc66;">=</span> LENGTH<span style="color: #66cc66;">&#40;</span>tableDesc<span style="color: #66cc66;">&#40;</span>i<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>col_name<span style="color: #66cc66;">&#41;</span>;
    END <span style="color: #993333; font-weight: bold;">IF</span>;
&nbsp;
    <span style="color: #808080; font-style: italic;">-- Replace non-displayable column values with displayable values.</span>
    <span style="color: #993333; font-weight: bold;">IF</span> i <span style="color: #66cc66;">&lt;</span> colCount THEN
      dynamic_stmt :<span style="color: #66cc66;">=</span> dynamic_stmt <span style="color: #66cc66;">||</span> check_column<span style="color: #66cc66;">&#40;</span>tableDesc<span style="color: #66cc66;">&#40;</span>i<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>col_name<span style="color: #66cc66;">,</span>tableDesc<span style="color: #66cc66;">&#40;</span>i<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>col_type<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">||</span> <span style="color: #ff0000;">' AS '</span>
                   <span style="color: #66cc66;">||</span> tableDesc<span style="color: #66cc66;">&#40;</span>i<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>col_name <span style="color: #66cc66;">||</span> <span style="color: #ff0000;">', '</span>;
    ELSE
      dynamic_stmt :<span style="color: #66cc66;">=</span> dynamic_stmt <span style="color: #66cc66;">||</span> check_column<span style="color: #66cc66;">&#40;</span>tableDesc<span style="color: #66cc66;">&#40;</span>i<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>col_name<span style="color: #66cc66;">,</span>tableDesc<span style="color: #66cc66;">&#40;</span>i<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>col_type<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">||</span> <span style="color: #ff0000;">' AS '</span>
                   <span style="color: #66cc66;">||</span> tableDesc<span style="color: #66cc66;">&#40;</span>i<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>col_name <span style="color: #66cc66;">||</span> <span style="color: #ff0000;">' '</span> <span style="color: #66cc66;">||</span> <span style="color: #ff0000;">'FROM '</span> <span style="color: #66cc66;">||</span> dbms_assert<span style="color: #66cc66;">.</span>simple_sql_name<span style="color: #66cc66;">&#40;</span>table_name<span style="color: #66cc66;">&#41;</span>
                   <span style="color: #66cc66;">||</span> <span style="color: #ff0000;">' '</span> <span style="color: #66cc66;">||</span> where_clause;
    END <span style="color: #993333; font-weight: bold;">IF</span>;
&nbsp;
  END LOOP;
&nbsp;
  <span style="color: #808080; font-style: italic;">-- Provide conditional debugging instruction that displays dynamically created query.</span>
  $IF $$DEBUG <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">1</span> $THEN
     dbms_output<span style="color: #66cc66;">.</span>put_line<span style="color: #66cc66;">&#40;</span>dynamic_stmt<span style="color: #66cc66;">&#41;</span>;
  $END
&nbsp;
  <span style="color: #808080; font-style: italic;">-- Prepare unfiltered display cursor. </span>
  dbms_sql<span style="color: #66cc66;">.</span>parse<span style="color: #66cc66;">&#40;</span>stmt<span style="color: #66cc66;">,</span> dynamic_stmt<span style="color: #66cc66;">,</span> dbms_sql<span style="color: #66cc66;">.</span>native<span style="color: #66cc66;">&#41;</span>;
&nbsp;
  <span style="color: #808080; font-style: italic;">-- Describe the table structure:</span>
  <span style="color: #808080; font-style: italic;">-- --------------------------------------------------------</span>
  <span style="color: #808080; font-style: italic;">--  1. Store metadata in tableDesc (reuse of existing variable)</span>
  <span style="color: #808080; font-style: italic;">--  2. Store the number of columns in colCount</span>
  <span style="color: #808080; font-style: italic;">-- --------------------------------------------------------</span>
  dbms_sql<span style="color: #66cc66;">.</span>describe_columns2<span style="color: #66cc66;">&#40;</span>stmt<span style="color: #66cc66;">,</span> colCount<span style="color: #66cc66;">,</span> tableDesc<span style="color: #66cc66;">&#41;</span>;
&nbsp;
  <span style="color: #808080; font-style: italic;">-- Define individual columns and assign value to colValue variable.</span>
  <span style="color: #993333; font-weight: bold;">FOR</span> i <span style="color: #993333; font-weight: bold;">IN</span> 1<span style="color: #66cc66;">..</span>colCount LOOP
    dbms_sql<span style="color: #66cc66;">.</span>define_column<span style="color: #66cc66;">&#40;</span>stmt<span style="color: #66cc66;">,</span> i<span style="color: #66cc66;">,</span> colValue<span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">4000</span><span style="color: #66cc66;">&#41;</span>;
  END LOOP;
&nbsp;
  <span style="color: #808080; font-style: italic;">-- Execute the dynamic cursor.</span>
  <span style="color: #993333; font-weight: bold;">STATUS</span> :<span style="color: #66cc66;">=</span> dbms_sql<span style="color: #66cc66;">.</span>execute<span style="color: #66cc66;">&#40;</span>stmt<span style="color: #66cc66;">&#41;</span>;
&nbsp;
  <span style="color: #808080; font-style: italic;">-- Fetch the results, row-by-row.</span>
  WHILE dbms_sql<span style="color: #66cc66;">.</span>fetch_rows<span style="color: #66cc66;">&#40;</span>stmt<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&gt;</span> <span style="color: #cc66cc;">0</span> LOOP
&nbsp;
    <span style="color: #808080; font-style: italic;">-- Reset row counter for display purposes.</span>
    rowIndex :<span style="color: #66cc66;">=</span> rowIndex <span style="color: #66cc66;">+</span> <span style="color: #cc66cc;">1</span>;
    dbms_output<span style="color: #66cc66;">.</span>put_line<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'********************************** '</span> <span style="color: #66cc66;">||</span> rowIndex <span style="color: #66cc66;">||</span> <span style="color: #ff0000;">'. row **********************************'</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
    <span style="color: #808080; font-style: italic;">-- For each column, print left-aligned column names and values.</span>
    <span style="color: #993333; font-weight: bold;">FOR</span> i <span style="color: #993333; font-weight: bold;">IN</span> 1<span style="color: #66cc66;">..</span>colCount LOOP
&nbsp;
      <span style="color: #808080; font-style: italic;">-- Limit display of long text.  </span>
      <span style="color: #993333; font-weight: bold;">IF</span> tableDesc<span style="color: #66cc66;">&#40;</span>i<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>col_type <span style="color: #993333; font-weight: bold;">IN</span> <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">9</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">96</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">112</span><span style="color: #66cc66;">&#41;</span> THEN
&nbsp;
        <span style="color: #808080; font-style: italic;">-- Display 40 character substrings of long text.  </span>
  	dbms_sql<span style="color: #66cc66;">.</span>column_value<span style="color: #66cc66;">&#40;</span>stmt<span style="color: #66cc66;">,</span> i<span style="color: #66cc66;">,</span> colValue<span style="color: #66cc66;">&#41;</span>;
        dbms_output<span style="color: #66cc66;">.</span>put_line<span style="color: #66cc66;">&#40;</span>RPAD<span style="color: #66cc66;">&#40;</span>tableDesc<span style="color: #66cc66;">&#40;</span>i<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>col_name<span style="color: #66cc66;">,</span> colLength<span style="color: #66cc66;">,</span><span style="color: #ff0000;">' '</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">||</span> <span style="color: #ff0000;">' : '</span> <span style="color: #66cc66;">||</span> SUBSTR<span style="color: #66cc66;">&#40;</span>colValue<span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">40</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;	  
&nbsp;
      ELSE
&nbsp;
        <span style="color: #808080; font-style: italic;">-- Display full value as character string.  </span>
        dbms_sql<span style="color: #66cc66;">.</span>column_value<span style="color: #66cc66;">&#40;</span>stmt<span style="color: #66cc66;">,</span> i<span style="color: #66cc66;">,</span> colValue<span style="color: #66cc66;">&#41;</span>;
        dbms_output<span style="color: #66cc66;">.</span>put_line<span style="color: #66cc66;">&#40;</span>RPAD<span style="color: #66cc66;">&#40;</span>tableDesc<span style="color: #66cc66;">&#40;</span>i<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>col_name<span style="color: #66cc66;">,</span> colLength<span style="color: #66cc66;">,</span><span style="color: #ff0000;">' '</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">||</span> <span style="color: #ff0000;">' : '</span> <span style="color: #66cc66;">||</span> colValue<span style="color: #66cc66;">&#41;</span>;
&nbsp;
      END <span style="color: #993333; font-weight: bold;">IF</span>;
&nbsp;
    END LOOP;
&nbsp;
  END LOOP;
&nbsp;
EXCEPTION
  <span style="color: #808080; font-style: italic;">-- Customer error handlers.</span>
  WHEN table_name_error THEN
    dbms_output<span style="color: #66cc66;">.</span>put_line<span style="color: #66cc66;">&#40;</span>SQLERRM<span style="color: #66cc66;">&#41;</span>;
  WHEN invalid_relational_operator THEN
    dbms_output<span style="color: #66cc66;">.</span>put_line<span style="color: #66cc66;">&#40;</span>SQLERRM<span style="color: #66cc66;">&#41;</span>;
  WHEN invalid_identifier THEN
    dbms_output<span style="color: #66cc66;">.</span>put_line<span style="color: #66cc66;">&#40;</span>SQLERRM<span style="color: #66cc66;">&#41;</span>;
  WHEN missing_keyword THEN
    dbms_output<span style="color: #66cc66;">.</span>put_line<span style="color: #66cc66;">&#40;</span>SQLERRM<span style="color: #66cc66;">&#41;</span>;
  WHEN misquoted_string THEN
    dbms_output<span style="color: #66cc66;">.</span>put_line<span style="color: #66cc66;">&#40;</span>SQLERRM<span style="color: #66cc66;">&#41;</span>;
  WHEN OTHERS THEN
    dbms_output<span style="color: #66cc66;">.</span>put_line<span style="color: #66cc66;">&#40;</span>SQLERRM<span style="color: #66cc66;">&#41;</span>;
END;
<span style="color: #66cc66;">/</span></pre></td></tr></table></div>

</div>
<p>You can run the procedure with the following syntax:</p>
<div style="code-panel650">

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;">EXECUTE display_vertical<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'ITEM'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'WHERE item_title LIKE '</span><span style="color: #ff0000;">'Star%'</span><span style="color: #ff0000;">''</span><span style="color: #66cc66;">&#41;</span>;</pre></div></div>

</div>
<p>It&#8217;ll return the following display of data:</p>
<div style="code-panel650">

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #66cc66;">**********************************</span> 1<span style="color: #66cc66;">.</span> row <span style="color: #66cc66;">**********************************</span>
ITEM_ID           : <span style="color: #cc66cc;">1002</span>
ITEM_BARCODE      : <span style="color: #cc66cc;">24543</span><span style="color: #66cc66;">-</span>02392
ITEM_TYPE         : <span style="color: #cc66cc;">1011</span>
ITEM_TITLE        : Star Wars I
ITEM_SUBTITLE     : Phantom Menace
ITEM_RATING       : PG
ITEM_RELEASE_DATE : 04<span style="color: #66cc66;">-</span>MAY<span style="color: #66cc66;">-</span><span style="color: #cc66cc;">99</span>
CREATED_BY        : <span style="color: #cc66cc;">3</span>
CREATION_DATE     : 09<span style="color: #66cc66;">-</span>JUN<span style="color: #66cc66;">-</span><span style="color: #cc66cc;">10</span>
LAST_UPDATED_BY   : <span style="color: #cc66cc;">3</span>
LAST_UPDATE_DATE  : 09<span style="color: #66cc66;">-</span>JUN<span style="color: #66cc66;">-</span><span style="color: #cc66cc;">10</span>
ITEM_DESC         :
DISPLAY_PHOTO     : BLOB <span style="color: #993333; font-weight: bold;">NOT</span> displayable<span style="color: #66cc66;">.</span>
<span style="color: #66cc66;">**********************************</span> 2<span style="color: #66cc66;">.</span> row <span style="color: #66cc66;">**********************************</span>
ITEM_ID           : <span style="color: #cc66cc;">1003</span>
ITEM_BARCODE      : <span style="color: #cc66cc;">24543</span><span style="color: #66cc66;">-</span><span style="color: #cc66cc;">5615</span>
ITEM_TYPE         : <span style="color: #cc66cc;">1010</span>
ITEM_TITLE        : Star Wars II
ITEM_SUBTITLE     : Attack of the Clones
ITEM_RATING       : PG
ITEM_RELEASE_DATE : <span style="color: #cc66cc;">16</span><span style="color: #66cc66;">-</span>MAY<span style="color: #66cc66;">-</span>02
CREATED_BY        : <span style="color: #cc66cc;">3</span>
CREATION_DATE     : 09<span style="color: #66cc66;">-</span>JUN<span style="color: #66cc66;">-</span><span style="color: #cc66cc;">10</span>
LAST_UPDATED_BY   : <span style="color: #cc66cc;">3</span>
LAST_UPDATE_DATE  : 09<span style="color: #66cc66;">-</span>JUN<span style="color: #66cc66;">-</span><span style="color: #cc66cc;">10</span>
ITEM_DESC         :
DISPLAY_PHOTO     : BLOB <span style="color: #993333; font-weight: bold;">NOT</span> displayable<span style="color: #66cc66;">.</span>
<span style="color: #66cc66;">**********************************</span> 3<span style="color: #66cc66;">.</span> row <span style="color: #66cc66;">**********************************</span>
ITEM_ID           : <span style="color: #cc66cc;">1004</span>
ITEM_BARCODE      : <span style="color: #cc66cc;">24543</span><span style="color: #66cc66;">-</span>05539
ITEM_TYPE         : <span style="color: #cc66cc;">1011</span>
ITEM_TITLE        : Star Wars II
ITEM_SUBTITLE     : Attack of the Clones
ITEM_RATING       : PG
ITEM_RELEASE_DATE : <span style="color: #cc66cc;">16</span><span style="color: #66cc66;">-</span>MAY<span style="color: #66cc66;">-</span>02
CREATED_BY        : <span style="color: #cc66cc;">3</span>
CREATION_DATE     : 09<span style="color: #66cc66;">-</span>JUN<span style="color: #66cc66;">-</span><span style="color: #cc66cc;">10</span>
LAST_UPDATED_BY   : <span style="color: #cc66cc;">3</span>
LAST_UPDATE_DATE  : 09<span style="color: #66cc66;">-</span>JUN<span style="color: #66cc66;">-</span><span style="color: #cc66cc;">10</span>
ITEM_DESC         : This <span style="color: #993333; font-weight: bold;">IS</span> designed <span style="color: #993333; font-weight: bold;">TO</span> be a long enough str
DISPLAY_PHOTO     : BLOB <span style="color: #993333; font-weight: bold;">NOT</span> displayable<span style="color: #66cc66;">.</span>
<span style="color: #66cc66;">**********************************</span> 4<span style="color: #66cc66;">.</span> row <span style="color: #66cc66;">**********************************</span>
ITEM_ID           : <span style="color: #cc66cc;">1005</span>
ITEM_BARCODE      : <span style="color: #cc66cc;">24543</span><span style="color: #66cc66;">-</span><span style="color: #cc66cc;">20309</span>
ITEM_TYPE         : <span style="color: #cc66cc;">1011</span>
ITEM_TITLE        : Star Wars III
ITEM_SUBTITLE     : Revenge of the Sith
ITEM_RATING       : PG13
ITEM_RELEASE_DATE : <span style="color: #cc66cc;">19</span><span style="color: #66cc66;">-</span>MAY<span style="color: #66cc66;">-</span>05
CREATED_BY        : <span style="color: #cc66cc;">3</span>
CREATION_DATE     : 09<span style="color: #66cc66;">-</span>JUN<span style="color: #66cc66;">-</span><span style="color: #cc66cc;">10</span>
LAST_UPDATED_BY   : <span style="color: #cc66cc;">3</span>
LAST_UPDATE_DATE  : 09<span style="color: #66cc66;">-</span>JUN<span style="color: #66cc66;">-</span><span style="color: #cc66cc;">10</span>
ITEM_DESC         :
DISPLAY_PHOTO     : BLOB <span style="color: #993333; font-weight: bold;">NOT</span> displayable<span style="color: #66cc66;">.</span></pre></div></div>

</div>
</div>
</div>
<p style="clear:both">
<div class="dropdownbox" style="padding-left:20px;background:#FFFFFF">
<p title="Click to see content ..." class="dropdownclick"><strong><em><span style="font-size:125%">Function for <code>\G</code> output</span></em></strong> <span>&darr;</span></p>
<p style="clear: both">
<p>The function is the best solution. It does have a dependency on a user-defined type (UDT). The function, like the procedure, only returns column values that are printable at the console. It also parses the first 40 characters from long text strings.
</p>
<p style="clear: both">
<div style="margin-left:20px">
<p>Before you create the function, you must create a UDT collection variable. The following syntax creates a schema-level UDT.</p>
<div style="code-panel650">

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">OR</span> <span style="color: #993333; font-weight: bold;">REPLACE</span> TYPE query_result <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #993333; font-weight: bold;">TABLE</span> OF VARCHAR2<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">77</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">/</span></pre></div></div>

</div>
<p>Here&#8217;s the function definition:</p>
<div style="code-panel650">

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
</pre></td><td class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">OR</span> <span style="color: #993333; font-weight: bold;">REPLACE</span> <span style="color: #993333; font-weight: bold;">FUNCTION</span> vertical_query
<span style="color: #66cc66;">&#40;</span> table_name VARCHAR2<span style="color: #66cc66;">,</span> where_clause VARCHAR2 <span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">RETURN</span> query_result <span style="color: #993333; font-weight: bold;">IS</span>
&nbsp;
  <span style="color: #808080; font-style: italic;">-- Open a cursor for a query against all columns in a table. </span>
  base_stmt	INTEGER :<span style="color: #66cc66;">=</span> dbms_sql<span style="color: #66cc66;">.</span>open_cursor;
&nbsp;
  <span style="color: #808080; font-style: italic;">-- Open a cursor for a dynamically constructed query, which excludes</span>
  <span style="color: #808080; font-style: italic;">-- any non-displayable columns with text.</span>
  stmt      INTEGER :<span style="color: #66cc66;">=</span> dbms_sql<span style="color: #66cc66;">.</span>open_cursor;
&nbsp;
  <span style="color: #808080; font-style: italic;">-- Declare local variables.</span>
  colValue	VARCHAR2<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">4000</span><span style="color: #66cc66;">&#41;</span>;      <span style="color: #808080; font-style: italic;">-- Declare a maximum string length for column values.</span>
  <span style="color: #993333; font-weight: bold;">STATUS</span>		INTEGER;             <span style="color: #808080; font-style: italic;">-- Declare a variable to hold acknowledgement of DBMS_SQL.EXECUTE</span>
  tableDesc	dbms_sql<span style="color: #66cc66;">.</span>desc_tab2;  <span style="color: #808080; font-style: italic;">-- Declare a table to hold metadata for the queries.</span>
  colCount	NUMBER;              <span style="color: #808080; font-style: italic;">-- Declare a variable for the column count.</span>
  rowIndex	NUMBER :<span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">0</span>;         <span style="color: #808080; font-style: italic;">-- for displaying the row number retrieved from the cursor</span>
  colLength	NUMBER :<span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">0</span>;         <span style="color: #808080; font-style: italic;">-- for keeping track of the length of the longest column name</span>
&nbsp;
  <span style="color: #808080; font-style: italic;">-- Declare local variable for the dynamically constructed query.</span>
  dynamic_stmt VARCHAR2<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">4000</span><span style="color: #66cc66;">&#41;</span> :<span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'SELECT '</span>;
&nbsp;
  <span style="color: #808080; font-style: italic;">-- Declare a index for the return collection.</span>
  rsIndex NUMBER :<span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">0</span>;
&nbsp;
  <span style="color: #808080; font-style: italic;">-- Declare a collection variable and instantiate the collection.</span>
  result_set QUERY_RESULT :<span style="color: #66cc66;">=</span> query_result<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
  <span style="color: #808080; font-style: italic;">-- Declare an exception for a bad table name, raised by a call to</span>
  <span style="color: #808080; font-style: italic;">-- the dbms_assert.qualified_sql_name function.</span>
  table_name_error EXCEPTION;
  PRAGMA EXCEPTION_INIT<span style="color: #66cc66;">&#40;</span>table_name_error<span style="color: #66cc66;">,</span> <span style="color: #66cc66;">-</span><span style="color: #cc66cc;">942</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
  <span style="color: #808080; font-style: italic;">-- Declare exception handlers for bad WHERE clause statements.</span>
&nbsp;
  <span style="color: #808080; font-style: italic;">-- Declare an exception for a missing WHERE keyword.</span>
  missing_keyword EXCEPTION;
  PRAGMA EXCEPTION_INIT<span style="color: #66cc66;">&#40;</span>missing_keyword<span style="color: #66cc66;">,</span> <span style="color: #66cc66;">-</span><span style="color: #cc66cc;">933</span><span style="color: #66cc66;">&#41;</span>;  
&nbsp;
  <span style="color: #808080; font-style: italic;">-- Declare an exception for a bad relational operator.</span>
  invalid_relational_operator EXCEPTION;
  PRAGMA EXCEPTION_INIT<span style="color: #66cc66;">&#40;</span>invalid_relational_operator<span style="color: #66cc66;">,</span> <span style="color: #66cc66;">-</span><span style="color: #cc66cc;">920</span><span style="color: #66cc66;">&#41;</span>;  
&nbsp;
  <span style="color: #808080; font-style: italic;">-- Declare an exception for a bad column name.</span>
  invalid_identifier EXCEPTION;
  PRAGMA EXCEPTION_INIT<span style="color: #66cc66;">&#40;</span>invalid_identifier<span style="color: #66cc66;">,</span> <span style="color: #66cc66;">-</span><span style="color: #cc66cc;">904</span><span style="color: #66cc66;">&#41;</span>;  
&nbsp;
  <span style="color: #808080; font-style: italic;">-- Declare an exception for a missing backquoted apostrophe.</span>
  misquoted_string EXCEPTION;
  PRAGMA EXCEPTION_INIT<span style="color: #66cc66;">&#40;</span>misquoted_string<span style="color: #66cc66;">,</span> <span style="color: #66cc66;">-</span><span style="color: #cc66cc;">1756</span><span style="color: #66cc66;">&#41;</span>;  
&nbsp;
  <span style="color: #808080; font-style: italic;">-- ------------------------------------------------------------------</span>
&nbsp;
  <span style="color: #808080; font-style: italic;">-- Declare a function that replaces non-displayable values with text messages.</span>
  <span style="color: #993333; font-weight: bold;">FUNCTION</span> check_column<span style="color: #66cc66;">&#40;</span> p_name   VARCHAR2
                       <span style="color: #66cc66;">,</span> p_type   NUMBER <span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">RETURN</span> VARCHAR2 <span style="color: #993333; font-weight: bold;">IS</span>
&nbsp;
    <span style="color: #808080; font-style: italic;">-- Return column name or literal value.</span>
    retval VARCHAR2<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">30</span><span style="color: #66cc66;">&#41;</span>;			   
&nbsp;
  BEGIN
&nbsp;
    <span style="color: #808080; font-style: italic;">-- Find strings, numbers, dates, timestamps, rowids and replace non-display values.</span>
    <span style="color: #993333; font-weight: bold;">IF</span> p_type <span style="color: #993333; font-weight: bold;">IN</span> <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">2</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">8</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">9</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">12</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">69</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">96</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">100</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">101</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">112</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">178</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">179</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">180</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">181</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">231</span><span style="color: #66cc66;">&#41;</span> THEN
&nbsp;
      <span style="color: #808080; font-style: italic;">-- Assign the column name for a displayable column value.</span>
      retval :<span style="color: #66cc66;">=</span> p_name;
&nbsp;
    ELSE
&nbsp;
      <span style="color: #808080; font-style: italic;">-- Re-assign string literals for column names where values aren't displayable.      </span>
      <span style="color: #993333; font-weight: bold;">SELECT</span> DECODE<span style="color: #66cc66;">&#40;</span>p_type<span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">23</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">''</span><span style="color: #ff0000;">'RAW not displayable.'</span><span style="color: #ff0000;">''</span>
                          <span style="color: #66cc66;">,</span><span style="color: #cc66cc;">105</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">''</span><span style="color: #ff0000;">'MLSLABEL not displayable.'</span><span style="color: #ff0000;">''</span>
                          <span style="color: #66cc66;">,</span><span style="color: #cc66cc;">106</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">''</span><span style="color: #ff0000;">'MLSLABEL not displayable.'</span><span style="color: #ff0000;">''</span>
                          <span style="color: #66cc66;">,</span><span style="color: #cc66cc;">113</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">''</span><span style="color: #ff0000;">'BLOB not displayable.'</span><span style="color: #ff0000;">''</span>
                          <span style="color: #66cc66;">,</span><span style="color: #cc66cc;">114</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">''</span><span style="color: #ff0000;">'BFILE not displayable.'</span><span style="color: #ff0000;">''</span>
                          <span style="color: #66cc66;">,</span><span style="color: #cc66cc;">115</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">''</span><span style="color: #ff0000;">'CFILE not displayable.'</span><span style="color: #ff0000;">''</span>
                          <span style="color: #66cc66;">,</span><span style="color: #ff0000;">''</span><span style="color: #ff0000;">'UNDEFINED not displayable.'</span><span style="color: #ff0000;">''</span><span style="color: #66cc66;">&#41;</span>
      <span style="color: #993333; font-weight: bold;">INTO</span> retval
      <span style="color: #993333; font-weight: bold;">FROM</span> dual;
&nbsp;
    END <span style="color: #993333; font-weight: bold;">IF</span>;
&nbsp;
    <span style="color: #808080; font-style: italic;">-- Return the column name or a apostrophe delimited string literal.</span>
    <span style="color: #993333; font-weight: bold;">RETURN</span> retval;
  END check_column;
&nbsp;
  <span style="color: #808080; font-style: italic;">-- ------------------------------------------------------------------</span>
&nbsp;
BEGIN
&nbsp;
	<span style="color: #808080; font-style: italic;">-- Prepare unfiltered display cursor.</span>
	dbms_sql<span style="color: #66cc66;">.</span>parse<span style="color: #66cc66;">&#40;</span>base_stmt<span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'SELECT * FROM '</span> <span style="color: #66cc66;">||</span> dbms_assert<span style="color: #66cc66;">.</span>simple_sql_name<span style="color: #66cc66;">&#40;</span>table_name<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">||</span> <span style="color: #ff0000;">' '</span> <span style="color: #66cc66;">||</span> where_clause<span style="color: #66cc66;">,</span> dbms_sql<span style="color: #66cc66;">.</span>native<span style="color: #66cc66;">&#41;</span>;
&nbsp;
  <span style="color: #808080; font-style: italic;">-- Describe the table structure:</span>
  <span style="color: #808080; font-style: italic;">-- --------------------------------------------------------</span>
  <span style="color: #808080; font-style: italic;">--  1. Store metadata in tableDesc</span>
  <span style="color: #808080; font-style: italic;">--  2. Store the number of columns in colCount</span>
  <span style="color: #808080; font-style: italic;">-- --------------------------------------------------------</span>
  dbms_sql<span style="color: #66cc66;">.</span>describe_columns2<span style="color: #66cc66;">&#40;</span>base_stmt<span style="color: #66cc66;">,</span> colCount<span style="color: #66cc66;">,</span> tableDesc<span style="color: #66cc66;">&#41;</span>;
&nbsp;
  <span style="color: #808080; font-style: italic;">-- Define individual columns and assign value to colValue variable.</span>
  <span style="color: #993333; font-weight: bold;">FOR</span> i <span style="color: #993333; font-weight: bold;">IN</span> 1<span style="color: #66cc66;">..</span>colCount LOOP
&nbsp;
    <span style="color: #808080; font-style: italic;">-- Define columns for each column returned into tableDesc.</span>
    dbms_sql<span style="color: #66cc66;">.</span>define_column<span style="color: #66cc66;">&#40;</span>base_stmt<span style="color: #66cc66;">,</span> i<span style="color: #66cc66;">,</span> colValue<span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">4000</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
    <span style="color: #808080; font-style: italic;">-- Find the length of the longest column name.</span>
    <span style="color: #993333; font-weight: bold;">IF</span> LENGTH<span style="color: #66cc66;">&#40;</span>tableDesc<span style="color: #66cc66;">&#40;</span>i<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>col_name<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&gt;</span> colLength THEN
      colLength :<span style="color: #66cc66;">=</span> LENGTH<span style="color: #66cc66;">&#40;</span>tableDesc<span style="color: #66cc66;">&#40;</span>i<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>col_name<span style="color: #66cc66;">&#41;</span>;
    END <span style="color: #993333; font-weight: bold;">IF</span>;
&nbsp;
    <span style="color: #808080; font-style: italic;">-- Replace non-displayable column values with displayable values.</span>
    <span style="color: #993333; font-weight: bold;">IF</span> i <span style="color: #66cc66;">&lt;</span> colCount THEN
      dynamic_stmt :<span style="color: #66cc66;">=</span> dynamic_stmt <span style="color: #66cc66;">||</span> check_column<span style="color: #66cc66;">&#40;</span>tableDesc<span style="color: #66cc66;">&#40;</span>i<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>col_name<span style="color: #66cc66;">,</span>tableDesc<span style="color: #66cc66;">&#40;</span>i<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>col_type<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">||</span> <span style="color: #ff0000;">' AS '</span>
                   <span style="color: #66cc66;">||</span> tableDesc<span style="color: #66cc66;">&#40;</span>i<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>col_name <span style="color: #66cc66;">||</span> <span style="color: #ff0000;">', '</span>;
    ELSE
      dynamic_stmt :<span style="color: #66cc66;">=</span> dynamic_stmt <span style="color: #66cc66;">||</span> check_column<span style="color: #66cc66;">&#40;</span>tableDesc<span style="color: #66cc66;">&#40;</span>i<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>col_name<span style="color: #66cc66;">,</span>tableDesc<span style="color: #66cc66;">&#40;</span>i<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>col_type<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">||</span> <span style="color: #ff0000;">' AS '</span>
                   <span style="color: #66cc66;">||</span> tableDesc<span style="color: #66cc66;">&#40;</span>i<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>col_name <span style="color: #66cc66;">||</span> <span style="color: #ff0000;">' '</span> <span style="color: #66cc66;">||</span> <span style="color: #ff0000;">'FROM '</span> <span style="color: #66cc66;">||</span> dbms_assert<span style="color: #66cc66;">.</span>simple_sql_name<span style="color: #66cc66;">&#40;</span>table_name<span style="color: #66cc66;">&#41;</span>
                   <span style="color: #66cc66;">||</span> <span style="color: #ff0000;">' '</span> <span style="color: #66cc66;">||</span> where_clause;
    END <span style="color: #993333; font-weight: bold;">IF</span>;
&nbsp;
  END LOOP;
&nbsp;
  <span style="color: #808080; font-style: italic;">-- Provide conditional debugging instruction that displays dynamically created query.</span>
  $IF $$DEBUG <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">1</span> $THEN
     dbms_output<span style="color: #66cc66;">.</span>put_line<span style="color: #66cc66;">&#40;</span>dynamic_stmt<span style="color: #66cc66;">&#41;</span>;
  $END
&nbsp;
  <span style="color: #808080; font-style: italic;">-- Prepare unfiltered display cursor. </span>
  dbms_sql<span style="color: #66cc66;">.</span>parse<span style="color: #66cc66;">&#40;</span>stmt<span style="color: #66cc66;">,</span> dynamic_stmt<span style="color: #66cc66;">,</span> dbms_sql<span style="color: #66cc66;">.</span>native<span style="color: #66cc66;">&#41;</span>;
&nbsp;
  <span style="color: #808080; font-style: italic;">-- Describe the table structure:</span>
  <span style="color: #808080; font-style: italic;">-- --------------------------------------------------------</span>
  <span style="color: #808080; font-style: italic;">--  1. Store metadata in tableDesc (reuse of existing variable)</span>
  <span style="color: #808080; font-style: italic;">--  2. Store the number of columns in colCount</span>
  <span style="color: #808080; font-style: italic;">-- --------------------------------------------------------</span>
  dbms_sql<span style="color: #66cc66;">.</span>describe_columns2<span style="color: #66cc66;">&#40;</span>stmt<span style="color: #66cc66;">,</span> colCount<span style="color: #66cc66;">,</span> tableDesc<span style="color: #66cc66;">&#41;</span>;
&nbsp;
  <span style="color: #808080; font-style: italic;">-- Define individual columns and assign value to colValue variable.</span>
  <span style="color: #993333; font-weight: bold;">FOR</span> i <span style="color: #993333; font-weight: bold;">IN</span> 1<span style="color: #66cc66;">..</span>colCount LOOP
    dbms_sql<span style="color: #66cc66;">.</span>define_column<span style="color: #66cc66;">&#40;</span>stmt<span style="color: #66cc66;">,</span> i<span style="color: #66cc66;">,</span> colValue<span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">4000</span><span style="color: #66cc66;">&#41;</span>;
  END LOOP;
&nbsp;
  <span style="color: #808080; font-style: italic;">-- Execute the dynamic cursor.</span>
  <span style="color: #993333; font-weight: bold;">STATUS</span> :<span style="color: #66cc66;">=</span> dbms_sql<span style="color: #66cc66;">.</span>execute<span style="color: #66cc66;">&#40;</span>stmt<span style="color: #66cc66;">&#41;</span>;
&nbsp;
  <span style="color: #808080; font-style: italic;">-- Fetch the results, row-by-row.</span>
  WHILE dbms_sql<span style="color: #66cc66;">.</span>fetch_rows<span style="color: #66cc66;">&#40;</span>stmt<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&gt;</span> <span style="color: #cc66cc;">0</span> LOOP
&nbsp;
    <span style="color: #808080; font-style: italic;">-- Reset row counter for output display purposes.</span>
    rowIndex :<span style="color: #66cc66;">=</span> rowIndex <span style="color: #66cc66;">+</span> <span style="color: #cc66cc;">1</span>;
&nbsp;
    <span style="color: #808080; font-style: italic;">-- Increment the counter for the collection and extend space before assignment.</span>
    rsIndex :<span style="color: #66cc66;">=</span> rsIndex <span style="color: #66cc66;">+</span> <span style="color: #cc66cc;">1</span>;
    result_set<span style="color: #66cc66;">.</span>EXTEND;
    result_set<span style="color: #66cc66;">&#40;</span>rsIndex<span style="color: #66cc66;">&#41;</span> :<span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'********************************** '</span> <span style="color: #66cc66;">||</span> rowIndex <span style="color: #66cc66;">||</span> <span style="color: #ff0000;">'. row **********************************'</span>;
&nbsp;
    <span style="color: #808080; font-style: italic;">-- For each column, print left-aligned column names and values.</span>
    <span style="color: #993333; font-weight: bold;">FOR</span> i <span style="color: #993333; font-weight: bold;">IN</span> 1<span style="color: #66cc66;">..</span>colCount LOOP
&nbsp;
      <span style="color: #808080; font-style: italic;">-- Increment the counter for the collection and extend space before assignment.</span>
      rsIndex :<span style="color: #66cc66;">=</span> rsIndex <span style="color: #66cc66;">+</span> <span style="color: #cc66cc;">1</span>;
      result_set<span style="color: #66cc66;">.</span>EXTEND;
&nbsp;
      <span style="color: #808080; font-style: italic;">-- Limit display of long text.  </span>
      <span style="color: #993333; font-weight: bold;">IF</span> tableDesc<span style="color: #66cc66;">&#40;</span>i<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>col_type <span style="color: #993333; font-weight: bold;">IN</span> <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">9</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">96</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">112</span><span style="color: #66cc66;">&#41;</span> THEN
&nbsp;
        <span style="color: #808080; font-style: italic;">-- Display 40 character substrings of long text.  </span>
        dbms_sql<span style="color: #66cc66;">.</span>column_value<span style="color: #66cc66;">&#40;</span>stmt<span style="color: #66cc66;">,</span> i<span style="color: #66cc66;">,</span> colValue<span style="color: #66cc66;">&#41;</span>;
        result_set<span style="color: #66cc66;">&#40;</span>rsIndex<span style="color: #66cc66;">&#41;</span> :<span style="color: #66cc66;">=</span> RPAD<span style="color: #66cc66;">&#40;</span>tableDesc<span style="color: #66cc66;">&#40;</span>i<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>col_name<span style="color: #66cc66;">,</span> colLength<span style="color: #66cc66;">,</span><span style="color: #ff0000;">' '</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">||</span> <span style="color: #ff0000;">' : '</span> <span style="color: #66cc66;">||</span> SUBSTR<span style="color: #66cc66;">&#40;</span>colValue<span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">40</span><span style="color: #66cc66;">&#41;</span>;	  
&nbsp;
      ELSE
&nbsp;
        <span style="color: #808080; font-style: italic;">-- Display full value as character string.  </span>
        dbms_sql<span style="color: #66cc66;">.</span>column_value<span style="color: #66cc66;">&#40;</span>stmt<span style="color: #66cc66;">,</span> i<span style="color: #66cc66;">,</span> colValue<span style="color: #66cc66;">&#41;</span>;
        result_set<span style="color: #66cc66;">&#40;</span>rsIndex<span style="color: #66cc66;">&#41;</span> :<span style="color: #66cc66;">=</span> RPAD<span style="color: #66cc66;">&#40;</span>tableDesc<span style="color: #66cc66;">&#40;</span>i<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>col_name<span style="color: #66cc66;">,</span> colLength<span style="color: #66cc66;">,</span><span style="color: #ff0000;">' '</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">||</span> <span style="color: #ff0000;">' : '</span> <span style="color: #66cc66;">||</span> colValue;
&nbsp;
      END <span style="color: #993333; font-weight: bold;">IF</span>;
&nbsp;
    END LOOP;
&nbsp;
  END LOOP;
&nbsp;
  <span style="color: #808080; font-style: italic;">-- Increment the counter for the collection and extend space before assignment.</span>
  <span style="color: #993333; font-weight: bold;">FOR</span> i <span style="color: #993333; font-weight: bold;">IN</span> 1<span style="color: #66cc66;">..</span>3 LOOP
    rsIndex :<span style="color: #66cc66;">=</span> rsIndex <span style="color: #66cc66;">+</span> <span style="color: #cc66cc;">1</span>;
    result_set<span style="color: #66cc66;">.</span>EXTEND;
&nbsp;
    CASE i
      WHEN <span style="color: #cc66cc;">1</span> THEN
        result_set<span style="color: #66cc66;">&#40;</span>rsIndex<span style="color: #66cc66;">&#41;</span> :<span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'****************************************************************************'</span>;
      WHEN <span style="color: #cc66cc;">2</span> THEN
        result_set<span style="color: #66cc66;">&#40;</span>rsIndex<span style="color: #66cc66;">&#41;</span> :<span style="color: #66cc66;">=</span> CHR<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">10</span><span style="color: #66cc66;">&#41;</span>;    
      WHEN <span style="color: #cc66cc;">3</span> THEN
        result_set<span style="color: #66cc66;">&#40;</span>rsIndex<span style="color: #66cc66;">&#41;</span> :<span style="color: #66cc66;">=</span> rowIndex <span style="color: #66cc66;">||</span> <span style="color: #ff0000;">' rows in set'</span>;    
    END CASE;
  END LOOP;
&nbsp;
  <span style="color: #808080; font-style: italic;">-- Return collection.</span>
  <span style="color: #993333; font-weight: bold;">RETURN</span> result_set;
EXCEPTION
  <span style="color: #808080; font-style: italic;">-- Customer error handlers, add specialized text or collapse into one with the OTHERS catchall.</span>
  WHEN table_name_error THEN
    dbms_output<span style="color: #66cc66;">.</span>put_line<span style="color: #66cc66;">&#40;</span>SQLERRM<span style="color: #66cc66;">&#41;</span>;
  WHEN invalid_relational_operator THEN
    dbms_output<span style="color: #66cc66;">.</span>put_line<span style="color: #66cc66;">&#40;</span>SQLERRM<span style="color: #66cc66;">&#41;</span>;
  WHEN invalid_identifier THEN
    dbms_output<span style="color: #66cc66;">.</span>put_line<span style="color: #66cc66;">&#40;</span>SQLERRM<span style="color: #66cc66;">&#41;</span>;
  WHEN missing_keyword THEN
    dbms_output<span style="color: #66cc66;">.</span>put_line<span style="color: #66cc66;">&#40;</span>SQLERRM<span style="color: #66cc66;">&#41;</span>;
  WHEN misquoted_string THEN
    dbms_output<span style="color: #66cc66;">.</span>put_line<span style="color: #66cc66;">&#40;</span>SQLERRM<span style="color: #66cc66;">&#41;</span>;
  WHEN OTHERS THEN
    dbms_output<span style="color: #66cc66;">.</span>put_line<span style="color: #66cc66;">&#40;</span>SQLERRM<span style="color: #66cc66;">&#41;</span>;
END;
<span style="color: #66cc66;">/</span></pre></td></tr></table></div>

</div>
<p>Before you attempt to run the function, you should set two Oracle SQL*Plus environment commands. One suppresses a message saying what just ran, and the other removes column headers. Clearly, the output is sufficient and the headers are clutter. You set these, as noted below:</p>
<div style="code-panel650">

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SET</span> FEEDBACK OFF
<span style="color: #993333; font-weight: bold;">SET</span> PAGESIZE <span style="color: #cc66cc;">0</span></pre></div></div>

</div>
<p>You can run the function with the following syntax (the <code>COLUMN_VALUE</code> is the standard name returned from a scalar schema-level collection.</p>
<div style="code-panel650">

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span> column_value
<span style="color: #993333; font-weight: bold;">FROM</span>   <span style="color: #993333; font-weight: bold;">TABLE</span><span style="color: #66cc66;">&#40;</span>vertical_query<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'ITEM'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'WHERE item_title LIKE '</span><span style="color: #ff0000;">'Star%'</span><span style="color: #ff0000;">''</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;</pre></div></div>

</div>
<p>It&#8217;ll return the following display of data:</p>
<div style="code-panel650">

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #66cc66;">**********************************</span> 1<span style="color: #66cc66;">.</span> row <span style="color: #66cc66;">**********************************</span>
ITEM_ID           : <span style="color: #cc66cc;">1002</span>
ITEM_BARCODE      : <span style="color: #cc66cc;">24543</span><span style="color: #66cc66;">-</span>02392
ITEM_TYPE         : <span style="color: #cc66cc;">1011</span>
ITEM_TITLE        : Star Wars I
ITEM_SUBTITLE     : Phantom Menace
ITEM_RATING       : PG
ITEM_RELEASE_DATE : 04<span style="color: #66cc66;">-</span>MAY<span style="color: #66cc66;">-</span><span style="color: #cc66cc;">99</span>
CREATED_BY        : <span style="color: #cc66cc;">3</span>
CREATION_DATE     : 09<span style="color: #66cc66;">-</span>JUN<span style="color: #66cc66;">-</span><span style="color: #cc66cc;">10</span>
LAST_UPDATED_BY   : <span style="color: #cc66cc;">3</span>
LAST_UPDATE_DATE  : 09<span style="color: #66cc66;">-</span>JUN<span style="color: #66cc66;">-</span><span style="color: #cc66cc;">10</span>
ITEM_DESC         :
DISPLAY_PHOTO     : BLOB <span style="color: #993333; font-weight: bold;">NOT</span> displayable<span style="color: #66cc66;">.</span>
<span style="color: #66cc66;">**********************************</span> 2<span style="color: #66cc66;">.</span> row <span style="color: #66cc66;">**********************************</span>
ITEM_ID           : <span style="color: #cc66cc;">1003</span>
ITEM_BARCODE      : <span style="color: #cc66cc;">24543</span><span style="color: #66cc66;">-</span><span style="color: #cc66cc;">5615</span>
ITEM_TYPE         : <span style="color: #cc66cc;">1010</span>
ITEM_TITLE        : Star Wars II
ITEM_SUBTITLE     : Attack of the Clones
ITEM_RATING       : PG
ITEM_RELEASE_DATE : <span style="color: #cc66cc;">16</span><span style="color: #66cc66;">-</span>MAY<span style="color: #66cc66;">-</span>02
CREATED_BY        : <span style="color: #cc66cc;">3</span>
CREATION_DATE     : 09<span style="color: #66cc66;">-</span>JUN<span style="color: #66cc66;">-</span><span style="color: #cc66cc;">10</span>
LAST_UPDATED_BY   : <span style="color: #cc66cc;">3</span>
LAST_UPDATE_DATE  : 09<span style="color: #66cc66;">-</span>JUN<span style="color: #66cc66;">-</span><span style="color: #cc66cc;">10</span>
ITEM_DESC         :
DISPLAY_PHOTO     : BLOB <span style="color: #993333; font-weight: bold;">NOT</span> displayable<span style="color: #66cc66;">.</span>
<span style="color: #66cc66;">**********************************</span> 3<span style="color: #66cc66;">.</span> row <span style="color: #66cc66;">**********************************</span>
ITEM_ID           : <span style="color: #cc66cc;">1004</span>
ITEM_BARCODE      : <span style="color: #cc66cc;">24543</span><span style="color: #66cc66;">-</span>05539
ITEM_TYPE         : <span style="color: #cc66cc;">1011</span>
ITEM_TITLE        : Star Wars II
ITEM_SUBTITLE     : Attack of the Clones
ITEM_RATING       : PG
ITEM_RELEASE_DATE : <span style="color: #cc66cc;">16</span><span style="color: #66cc66;">-</span>MAY<span style="color: #66cc66;">-</span>02
CREATED_BY        : <span style="color: #cc66cc;">3</span>
CREATION_DATE     : 09<span style="color: #66cc66;">-</span>JUN<span style="color: #66cc66;">-</span><span style="color: #cc66cc;">10</span>
LAST_UPDATED_BY   : <span style="color: #cc66cc;">3</span>
LAST_UPDATE_DATE  : 09<span style="color: #66cc66;">-</span>JUN<span style="color: #66cc66;">-</span><span style="color: #cc66cc;">10</span>
ITEM_DESC         : This <span style="color: #993333; font-weight: bold;">IS</span> designed <span style="color: #993333; font-weight: bold;">TO</span> be a long enough str
DISPLAY_PHOTO     : BLOB <span style="color: #993333; font-weight: bold;">NOT</span> displayable<span style="color: #66cc66;">.</span>
<span style="color: #66cc66;">**********************************</span> 4<span style="color: #66cc66;">.</span> row <span style="color: #66cc66;">**********************************</span>
ITEM_ID           : <span style="color: #cc66cc;">1005</span>
ITEM_BARCODE      : <span style="color: #cc66cc;">24543</span><span style="color: #66cc66;">-</span><span style="color: #cc66cc;">20309</span>
ITEM_TYPE         : <span style="color: #cc66cc;">1011</span>
ITEM_TITLE        : Star Wars III
ITEM_SUBTITLE     : Revenge of the Sith
ITEM_RATING       : PG13
ITEM_RELEASE_DATE : <span style="color: #cc66cc;">19</span><span style="color: #66cc66;">-</span>MAY<span style="color: #66cc66;">-</span>05
CREATED_BY        : <span style="color: #cc66cc;">3</span>
CREATION_DATE     : 09<span style="color: #66cc66;">-</span>JUN<span style="color: #66cc66;">-</span><span style="color: #cc66cc;">10</span>
LAST_UPDATED_BY   : <span style="color: #cc66cc;">3</span>
LAST_UPDATE_DATE  : 09<span style="color: #66cc66;">-</span>JUN<span style="color: #66cc66;">-</span><span style="color: #cc66cc;">10</span>
ITEM_DESC         :
DISPLAY_PHOTO     : BLOB <span style="color: #993333; font-weight: bold;">NOT</span> displayable<span style="color: #66cc66;">.</span>
<span style="color: #66cc66;">****************************************************************************</span></pre></div></div>

</div>
</div>
</div>
<p>As usual, I hope this helps folks.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.mclaughlinsoftware.com/2010/06/14/a-g-option-for-oracle/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Goodbye to my iPhone</title>
		<link>http://blog.mclaughlinsoftware.com/2010/06/13/goodbye-to-my-iphone/</link>
		<comments>http://blog.mclaughlinsoftware.com/2010/06/13/goodbye-to-my-iphone/#comments</comments>
		<pubDate>Sun, 13 Jun 2010 06:55:20 +0000</pubDate>
		<dc:creator>maclochlainn</dc:creator>
				<category><![CDATA[EVO]]></category>
		<category><![CDATA[iPhone]]></category>

		<guid isPermaLink="false">http://blog.mclaughlinsoftware.com/?p=3954</guid>
		<description><![CDATA[For almost two years, I&#8217;ve loved my iPhone. That&#8217;s amazing, since I live where AT&#038;T has never provided 3G coverage. The contract expires this summer. Admittedly, business trips were refreshing because I generally always had a 3G connection. That is, until the last six months or so. During that period of time, I&#8217;ve been experiencing [...]]]></description>
			<content:encoded><![CDATA[<p>For almost two years, I&#8217;ve loved my iPhone. That&#8217;s amazing, since I live where AT&#038;T has never provided 3G coverage. The contract expires this summer.</p>
<p>Admittedly, business trips were refreshing because I generally always had a 3G connection. That is, until the last six months or so. During that period of time, I&#8217;ve been experiencing some random dropped calls. For example, AT&#038;T dropped my 3G connections about 8 times in less than 30 minutes in April. All three calls went over 5 minutes before they were dropped, and they were made from a hotel in Anaheim, California (near Angels Stadium). Those drops certainly made it appear that their system couldn&#8217;t handle the volume of concurrent calls, but it could have been something else. <img src='http://blog.mclaughlinsoftware.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p>The final straw was AT&#038;T&#8217;s unlimited data plan change announcement. Wow! It caught me by surprise. Their back peddling with a subsequent announcement of qualified renewed contracts doesn&#8217;t work for me. They&#8217;ve lost what little trust I had for them.</p>
<p>Fortunately, I&#8217;d deferred buying an iPad. I&#8217;d planned to order an iPad 3G model this last week, but now it will definitely be a Wi-Fi only device! I&#8217;m also deferring the purchase now to see if there&#8217;s another surprise in the wings.</p>
<p>When I compare the cost of my iPhone against the HTC EVO, the iPhone loses. I found Daniel Lyon&#8217;s article <a href="http://www.newsweek.com/2010/06/12/phone-fight.html"><em>Phone Fight!</em></a> interesting for many reasons. While his comparison of Microsoft versus Apple of yesteryear to Google versus Apple of today is interesting, this quote strikes me:</p>
<div style="padding-left:30px;padding-right:30px;font-style:italic">
&#8220;Right now the most advanced smart phone on the market is arguably not the new iPhone 4 but rather an Android device called the EVO 4G, made by HTC, a Taiwanese company. That phone has front and rear cameras, and shoots hi-def video, just like the new iPhone 4. But the EVO has a bigger display, its camera shoots in higher resolution, and it can turn itself into a mobile Wi-Fi hotspot, something the iPhone 4 can’t do.&#8221;
</div>
<p style="both:none">
<p>The mobile Wi-Fi hotspot means my iPad Wi-Fi works virtually anywhere. That alone is probably the single most important reason why I considered dropping my iPhone. Alas, I was disabused of the notion today by <a href="http://www.nytimes.com/2010/06/17/technology/personaltech/17pogue.html">David Pogue</a> (6/17/2010). The battery life is pathetic.</p>
<p>Let&#8217;s face it: the iPhone interface is AWESOME! Therefore, my idea of replacing my iPhone with an EVO will be a nearly forgotten memory, like my <a href="http://en.wikipedia.org/wiki/HP-25C">HP-25C</a> of college days and <a href="http://en.wikipedia.org/wiki/Star_Wars_IV">Star Wars IV</a> premiere gone by &#8230; </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.mclaughlinsoftware.com/2010/06/13/goodbye-to-my-iphone/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
