<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Reference Cursors &#8211; Why, when, and how?</title>
	<atom:link href="http://blog.mclaughlinsoftware.com/2008/10/11/reference-cursors-why-when-and-how/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.mclaughlinsoftware.com/2008/10/11/reference-cursors-why-when-and-how/</link>
	<description>Michael McLaughlin's Technical Blog</description>
	<lastBuildDate>Mon, 15 Mar 2010 01:07:23 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: maclochlainn</title>
		<link>http://blog.mclaughlinsoftware.com/2008/10/11/reference-cursors-why-when-and-how/comment-page-1/#comment-16244</link>
		<dc:creator>maclochlainn</dc:creator>
		<pubDate>Sun, 07 Feb 2010 01:28:52 +0000</pubDate>
		<guid isPermaLink="false">http://maclochlainn.wordpress.com/?p=563#comment-16244</guid>
		<description>What you&#039;d like to do is implement &lt;a href=&quot;http://blog.mclaughlinsoftware.com/2008/10/31/adapter-or-not-adapter-thats-the-question/&quot; rel=&quot;nofollow&quot;&gt;the Adapter Patter natively&lt;/a&gt; in PL/SQL. I would like that functionality too, but it doesn&#039;t exist. If you&#039;re client tool can query a result set through OCI8, like the link to an early post, then you can do it. The only way I&#039;ve been able to accomplish it is through OCI8 with PHP. I&#039;m sure it&#039;ll work in C/C++ too, and I&#039;ve heard it works in C#.</description>
		<content:encoded><![CDATA[<p>What you&#8217;d like to do is implement <a href="http://blog.mclaughlinsoftware.com/2008/10/31/adapter-or-not-adapter-thats-the-question/" rel="nofollow">the Adapter Patter natively</a> in PL/SQL. I would like that functionality too, but it doesn&#8217;t exist. If you&#8217;re client tool can query a result set through OCI8, like the link to an early post, then you can do it. The only way I&#8217;ve been able to accomplish it is through OCI8 with PHP. I&#8217;m sure it&#8217;ll work in C/C++ too, and I&#8217;ve heard it works in C#.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Guy</title>
		<link>http://blog.mclaughlinsoftware.com/2008/10/11/reference-cursors-why-when-and-how/comment-page-1/#comment-16229</link>
		<dc:creator>Guy</dc:creator>
		<pubDate>Sat, 06 Feb 2010 21:52:25 +0000</pubDate>
		<guid isPermaLink="false">http://maclochlainn.wordpress.com/?p=563#comment-16229</guid>
		<description>Is there way of using table functions when you don&#039;t know what kind of TABLE OF TYPE you will be piping back?

For example, imagine I have a package. That package contains a function that accepts arguments, builds a dynamic SELECT and stores the results of that SELECT in a REF CURSOR. 

This is where the problem starts. I now want to pipeline the REF CURSOR rows. Using the REF CURSOR as the function output, and doing a TABLE(function) on it doesn&#039;t work - as you showed in your article.

So I thought, why not dynamically build a new type (DYNTYPE) on the basis of your REF CURSOR metadata inside your package. This could happen inside an extra procedure which you call at the end of your first function. 

You would then write an extra function that accepts the REF CURSOR as input and pipelines a TABLE OF DYNTYPE, and we&#039;re done. 

But the question is - how do you create a type on the basis of REF CURSOR metadata inside a package? 

And if this approach doesn&#039;t work, can you make any other suggestion for pipelining when the number and types of underlying columns of your REF CURSOR is unknown at design time?

This would be a very flexible tool. 

(In my case it&#039;s actually the only way to go because my client application (S-Plus) will only receive data if you hard-code a SQL statemtent or if you pipeline a table function back to it.)</description>
		<content:encoded><![CDATA[<p>Is there way of using table functions when you don&#8217;t know what kind of TABLE OF TYPE you will be piping back?</p>
<p>For example, imagine I have a package. That package contains a function that accepts arguments, builds a dynamic SELECT and stores the results of that SELECT in a REF CURSOR. </p>
<p>This is where the problem starts. I now want to pipeline the REF CURSOR rows. Using the REF CURSOR as the function output, and doing a TABLE(function) on it doesn&#8217;t work &#8211; as you showed in your article.</p>
<p>So I thought, why not dynamically build a new type (DYNTYPE) on the basis of your REF CURSOR metadata inside your package. This could happen inside an extra procedure which you call at the end of your first function. </p>
<p>You would then write an extra function that accepts the REF CURSOR as input and pipelines a TABLE OF DYNTYPE, and we&#8217;re done. </p>
<p>But the question is &#8211; how do you create a type on the basis of REF CURSOR metadata inside a package? </p>
<p>And if this approach doesn&#8217;t work, can you make any other suggestion for pipelining when the number and types of underlying columns of your REF CURSOR is unknown at design time?</p>
<p>This would be a very flexible tool. </p>
<p>(In my case it&#8217;s actually the only way to go because my client application (S-Plus) will only receive data if you hard-code a SQL statemtent or if you pipeline a table function back to it.)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: maclochlainn</title>
		<link>http://blog.mclaughlinsoftware.com/2008/10/11/reference-cursors-why-when-and-how/comment-page-1/#comment-3489</link>
		<dc:creator>maclochlainn</dc:creator>
		<pubDate>Wed, 29 Apr 2009 05:08:13 +0000</pubDate>
		<guid isPermaLink="false">http://maclochlainn.wordpress.com/?p=563#comment-3489</guid>
		<description>You&#039;ve posed an interesting question but do your users really want a million records back to a web form?

I&#039;d suggest if you query the possible number of row returns before querying the data. When the number or rows exceeds a reasonable set, prompt the end-user with the opportunity to download a CSV file. If they say yes, then use the &lt;code&gt;LIMIT&lt;/code&gt; syntax like this to write blocks of rows that fit within your allocate SGA memory constraints. I&#039;d recommend an external table because you can perform bulk writes. Make sure you set up the external table with SQL*Loader not Data Pump. You could also use a Java program to write it to a non-Oracle owned directory with something like this &lt;a href=&quot;http://blog.mclaughlinsoftware.com/java-programming/how-to-copy-external-files-with-java-and-plsql-wrappers/&quot; rel=&quot;nofollow&quot;&gt;blog post&lt;/a&gt;.

&lt;pre lang=&quot;PLSQL&quot;&gt;
OPEN c;
LOOP
  FETCH c BULK COLLECT INTO record_type LIMIT 1000;
  EXIT WHEN record_type.COUNT = 0;
  FOR i IN 1..record_type.COUNT LOOP
    ... write logic ...
  END LOOP;
END LOOP;
&lt;/pre&gt;

Since you&#039;re in Java it might be more effective to simply write the data streams to the middle-tier. I hope this helps but if I misunderstood let me know.</description>
		<content:encoded><![CDATA[<p>You&#8217;ve posed an interesting question but do your users really want a million records back to a web form?</p>
<p>I&#8217;d suggest if you query the possible number of row returns before querying the data. When the number or rows exceeds a reasonable set, prompt the end-user with the opportunity to download a CSV file. If they say yes, then use the <code>LIMIT</code> syntax like this to write blocks of rows that fit within your allocate SGA memory constraints. I&#8217;d recommend an external table because you can perform bulk writes. Make sure you set up the external table with SQL*Loader not Data Pump. You could also use a Java program to write it to a non-Oracle owned directory with something like this <a href="http://blog.mclaughlinsoftware.com/java-programming/how-to-copy-external-files-with-java-and-plsql-wrappers/" rel="nofollow">blog post</a>.</p>

<div class="wp_syntax"><div class="code"><pre class="plsql" style="font-family:monospace;"><span style="color: #00F;">OPEN</span> c<span style="color: #00F;">;</span>
<span style="color: #00F;">LOOP</span>
  <span style="color: #00F;">FETCH</span> c <span style="color: #00F;">BULK</span> <span style="color: #00F;">COLLECT</span> <span style="color: #00F;">INTO</span> record_type LIMIT <span style="color: #800;">1000</span><span style="color: #00F;">;</span>
  <span style="color: #00F;">EXIT</span> <span style="color: #00F;">WHEN</span> record_type<span style="color: #00F;">.</span><span style="color: #000;">COUNT</span> <span style="color: #00F;">=</span> <span style="color: #800;">0</span><span style="color: #00F;">;</span>
  <span style="color: #00F;">FOR</span> i <span style="color: #00F;">IN</span> 1<span style="color: #00F;">..</span>record_type<span style="color: #00F;">.</span><span style="color: #000;">COUNT</span> <span style="color: #00F;">LOOP</span>
    <span style="color: #00F;">...</span> <span style="color: #00F;">WRITE</span> logic <span style="color: #00F;">...</span>
  <span style="color: #00F;">END</span> <span style="color: #00F;">LOOP</span><span style="color: #00F;">;</span>
<span style="color: #00F;">END</span> <span style="color: #00F;">LOOP</span><span style="color: #00F;">;</span></pre></div></div>

<p>Since you&#8217;re in Java it might be more effective to simply write the data streams to the middle-tier. I hope this helps but if I misunderstood let me know.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Richard</title>
		<link>http://blog.mclaughlinsoftware.com/2008/10/11/reference-cursors-why-when-and-how/comment-page-1/#comment-3470</link>
		<dc:creator>Richard</dc:creator>
		<pubDate>Tue, 28 Apr 2009 22:03:39 +0000</pubDate>
		<guid isPermaLink="false">http://maclochlainn.wordpress.com/?p=563#comment-3470</guid>
		<description>I am trying to use table functions as a way to stop replicating large volumes of data into my operational data store and evolve into a more federated or EII environment. Some source systems of ours only have web services available as a means to retrieve data so what I have been able to do so far to get at their information from my database using SQL is:

Oracle view -&gt; Oracle package/pipelined table function -&gt; Oracle java -&gt; Source system web service

Works great and fast when I issue &#039;select * from view where id = 1&#039;. The problem is I cannot prevent an individual or a software tool from issuing &#039;select * from view&#039;. Without the where clause the table function will bog down my database and network trying to pull back hundreds of millions of rows. I cannot try to artificially scale back the table function&#039;s incoming ref cursor using rownum because someone could ask the legit question &#039;select * from view where month = 1&#039; and get back an incomplete set of data. Any advise or experience in this regard that you could offer me?</description>
		<content:encoded><![CDATA[<p>I am trying to use table functions as a way to stop replicating large volumes of data into my operational data store and evolve into a more federated or EII environment. Some source systems of ours only have web services available as a means to retrieve data so what I have been able to do so far to get at their information from my database using SQL is:</p>
<p>Oracle view -&gt; Oracle package/pipelined table function -&gt; Oracle java -&gt; Source system web service</p>
<p>Works great and fast when I issue &#8217;select * from view where id = 1&#8242;. The problem is I cannot prevent an individual or a software tool from issuing &#8217;select * from view&#8217;. Without the where clause the table function will bog down my database and network trying to pull back hundreds of millions of rows. I cannot try to artificially scale back the table function&#8217;s incoming ref cursor using rownum because someone could ask the legit question &#8217;select * from view where month = 1&#8242; and get back an incomplete set of data. Any advise or experience in this regard that you could offer me?</p>
]]></content:encoded>
	</item>
</channel>
</rss>
