<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: Getting output from Ref Cursors in PL/SQL</title>
	<atom:link href="http://mikesmithers.wordpress.com/2010/09/13/getting-output-from-ref-cursors-in-plsql/feed/" rel="self" type="application/rss+xml" />
	<link>http://mikesmithers.wordpress.com/2010/09/13/getting-output-from-ref-cursors-in-plsql/</link>
	<description>Oracle - for when it was like that when you got there</description>
	<lastBuildDate>Sun, 26 May 2013 04:55:07 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
	<item>
		<title>By: Natalie</title>
		<link>http://mikesmithers.wordpress.com/2010/09/13/getting-output-from-ref-cursors-in-plsql/#comment-20817</link>
		<dc:creator><![CDATA[Natalie]]></dc:creator>
		<pubDate>Tue, 31 Jul 2012 12:18:14 +0000</pubDate>
		<guid isPermaLink="false">http://mikesmithers.wordpress.com/?p=571#comment-20817</guid>
		<description><![CDATA[Thank you! Not your complete aim, I&#039;m aware, but finding the row output count in your example was just what I was after!]]></description>
		<content:encoded><![CDATA[<p>Thank you! Not your complete aim, I&#8217;m aware, but finding the row output count in your example was just what I was after!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: mikesmithers</title>
		<link>http://mikesmithers.wordpress.com/2010/09/13/getting-output-from-ref-cursors-in-plsql/#comment-11130</link>
		<dc:creator><![CDATA[mikesmithers]]></dc:creator>
		<pubDate>Wed, 16 Nov 2011 13:28:01 +0000</pubDate>
		<guid isPermaLink="false">http://mikesmithers.wordpress.com/?p=571#comment-11130</guid>
		<description><![CDATA[Hi,

it looks like &lt;em&gt;custodian_extract_header&lt;/em&gt; is a cursor.
If this is the case, then the simplest way to make sure that your &lt;em&gt;ce_line&lt;/em&gt; variable is of the appropriate type is to define it as a record of the cursor record. Declare the variable after you&#039;ve declared the cursor like this :
[sourcecode light=&quot;true&quot;]
ce_line custodian_extract_header%ROWTYPE;
[/sourcecode]

You can then fetch the cursor into this record. However, you will have to convert the separate cursor elements into a VARCHAR2 before writing to the file.
So, if for example your cursor is returning a number, a date, and a varchar like this :
[sourcecode]
CURSOR custodian_extract_header IS
   SELECT my_num, my_date, my_char
   FROM some_table;
[/sourcecode]
... you would need to build the string to write to the file as follows ( assuming that l_buffer is declared as a varchar2(4000) and that you want to output comma separated values)...
[sourcecode light=&quot;true&quot;]
...
l_buffer := ce_line.my_num&#124;&#124;&#039;,&#039;&#124;&#124;TO_CHAR(ce_line.my_date)&#124;&#124;&#039;,&#039;&#124;&#124;ce_line.my_char;
UTL_FILE(ce_file, ce_line, FALSE);
[/sourcecode]

HTH

Mike]]></description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>it looks like <em>custodian_extract_header</em> is a cursor.<br />
If this is the case, then the simplest way to make sure that your <em>ce_line</em> variable is of the appropriate type is to define it as a record of the cursor record. Declare the variable after you&#8217;ve declared the cursor like this :</p>
<pre class="brush: plain; light: true; title: ; notranslate">
ce_line custodian_extract_header%ROWTYPE;
</pre>
<p>You can then fetch the cursor into this record. However, you will have to convert the separate cursor elements into a VARCHAR2 before writing to the file.<br />
So, if for example your cursor is returning a number, a date, and a varchar like this :</p>
<pre class="brush: plain; title: ; notranslate">
CURSOR custodian_extract_header IS
   SELECT my_num, my_date, my_char
   FROM some_table;
</pre>
<p>&#8230; you would need to build the string to write to the file as follows ( assuming that l_buffer is declared as a varchar2(4000) and that you want to output comma separated values)&#8230;</p>
<pre class="brush: plain; light: true; title: ; notranslate">
...
l_buffer := ce_line.my_num||','||TO_CHAR(ce_line.my_date)||','||ce_line.my_char;
UTL_FILE(ce_file, ce_line, FALSE);
</pre>
<p>HTH</p>
<p>Mike</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Developer</title>
		<link>http://mikesmithers.wordpress.com/2010/09/13/getting-output-from-ref-cursors-in-plsql/#comment-11074</link>
		<dc:creator><![CDATA[Developer]]></dc:creator>
		<pubDate>Tue, 15 Nov 2011 17:52:24 +0000</pubDate>
		<guid isPermaLink="false">http://mikesmithers.wordpress.com/?p=571#comment-11074</guid>
		<description><![CDATA[Thanks for the prompt response,
I am using the following code and get the error as Data type inconsistent Error.
Getting Error at      FETCH custodian_extract_header
             INTO  ce_line; since i have many columns with different date types and i have defined ce_line as Varchar 2  it giving me inconsistent data type.

If i select only VARCHAR columns for my V_CHR_SQL, the  below code runs perfectly fine.

I need to know what data type has to be defined for ce_line so that it accepts any datatype.

Decleare:
ce_line       varchar2(20000);
      V_DB_DIR_NAME    varchar2 (34)       := &#039; &#039;;
      ce_file         UTL_FILE.file_type;

Body:

open custodian_extract_header for V_CHR_SQL;

      IF UTL_FILE.is_open (ce_file)
      THEN
         LOOP
            FETCH custodian_extract_header
             INTO  ce_line;

            EXIT WHEN custodian_extract_header%NOTFOUND;

            UTL_FILE.put_line (ce_file, ce_line, FALSE);
         END LOOP;
      END IF;

      CLOSE custodian_extract_header;
      UTL_FILE.fclose (ce_file);]]></description>
		<content:encoded><![CDATA[<p>Thanks for the prompt response,<br />
I am using the following code and get the error as Data type inconsistent Error.<br />
Getting Error at      FETCH custodian_extract_header<br />
             INTO  ce_line; since i have many columns with different date types and i have defined ce_line as Varchar 2  it giving me inconsistent data type.</p>
<p>If i select only VARCHAR columns for my V_CHR_SQL, the  below code runs perfectly fine.</p>
<p>I need to know what data type has to be defined for ce_line so that it accepts any datatype.</p>
<p>Decleare:<br />
ce_line       varchar2(20000);<br />
      V_DB_DIR_NAME    varchar2 (34)       := &#8216; &#8216;;<br />
      ce_file         UTL_FILE.file_type;</p>
<p>Body:</p>
<p>open custodian_extract_header for V_CHR_SQL;</p>
<p>      IF UTL_FILE.is_open (ce_file)<br />
      THEN<br />
         LOOP<br />
            FETCH custodian_extract_header<br />
             INTO  ce_line;</p>
<p>            EXIT WHEN custodian_extract_header%NOTFOUND;</p>
<p>            UTL_FILE.put_line (ce_file, ce_line, FALSE);<br />
         END LOOP;<br />
      END IF;</p>
<p>      CLOSE custodian_extract_header;<br />
      UTL_FILE.fclose (ce_file);</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: mikesmithers</title>
		<link>http://mikesmithers.wordpress.com/2010/09/13/getting-output-from-ref-cursors-in-plsql/#comment-11071</link>
		<dc:creator><![CDATA[mikesmithers]]></dc:creator>
		<pubDate>Tue, 15 Nov 2011 17:28:36 +0000</pubDate>
		<guid isPermaLink="false">http://mikesmithers.wordpress.com/?p=571#comment-11071</guid>
		<description><![CDATA[Hi,

From what you&#039;ve said, I&#039;m assuming that :

1) The structure of the ref cursor you are querying (i.e. the fields it contains) is known at runtime
2) You are running on a unix based os ( hence CRON)
3) You want this job to run at regular intervals ( presumably once per day, overnight).

There are also a couple of questions :

1) Do you have the option of using DBMS_SCHEDULER to run the job entirely from within the database ? ( You can see examples of this &lt;a href=&quot;http://wp.me/pweWl-iQ&quot; rel=&quot;nofollow&quot;&gt;here&lt;/a&gt;. 
2) Are you restricted as to where you can create the output file ( does it have to be in a certain directory ?)

If you want to go down the DBMS_SCHEDULER route, you can use the UTL_FILE package to write the file out to a directory that you&#039;ve defined in the database.
There&#039;s an example of how to use UTL_FILE &lt;a href=&quot;http://wp.me/pweWl-9H&quot; rel=&quot;nofollow&quot;&gt;here&lt;/a&gt;. 
Alternatively, you could create an anonymous PL/SQL block saved in a file ( and use DBMS_OUTPUT), call this from a shell script and use the SQL*Plus spool command to create your file.
There&#039;s an example of invoking SQL*Plus from a shell script &lt;a href=&quot;http://wp.me/pweWl-7A&quot; rel=&quot;nofollow&quot;&gt;here&lt;/a&gt;.

HTH

Mike]]></description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>From what you&#8217;ve said, I&#8217;m assuming that :</p>
<p>1) The structure of the ref cursor you are querying (i.e. the fields it contains) is known at runtime<br />
2) You are running on a unix based os ( hence CRON)<br />
3) You want this job to run at regular intervals ( presumably once per day, overnight).</p>
<p>There are also a couple of questions :</p>
<p>1) Do you have the option of using DBMS_SCHEDULER to run the job entirely from within the database ? ( You can see examples of this <a href="http://wp.me/pweWl-iQ" rel="nofollow">here</a>.<br />
2) Are you restricted as to where you can create the output file ( does it have to be in a certain directory ?)</p>
<p>If you want to go down the DBMS_SCHEDULER route, you can use the UTL_FILE package to write the file out to a directory that you&#8217;ve defined in the database.<br />
There&#8217;s an example of how to use UTL_FILE <a href="http://wp.me/pweWl-9H" rel="nofollow">here</a>.<br />
Alternatively, you could create an anonymous PL/SQL block saved in a file ( and use DBMS_OUTPUT), call this from a shell script and use the SQL*Plus spool command to create your file.<br />
There&#8217;s an example of invoking SQL*Plus from a shell script <a href="http://wp.me/pweWl-7A" rel="nofollow">here</a>.</p>
<p>HTH</p>
<p>Mike</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Developer</title>
		<link>http://mikesmithers.wordpress.com/2010/09/13/getting-output-from-ref-cursors-in-plsql/#comment-10969</link>
		<dc:creator><![CDATA[Developer]]></dc:creator>
		<pubDate>Mon, 14 Nov 2011 14:36:22 +0000</pubDate>
		<guid isPermaLink="false">http://mikesmithers.wordpress.com/?p=571#comment-10969</guid>
		<description><![CDATA[I have to set a Cron job to run the package/procedure on a daily basis.
Within the procedure , I have a ref cursor and i need to convert the data into a CSV or excel file . This proc will be called in a cron job and the output file will be placed in some folder within server or networl Drive , Please help

Expample
		v_chr_sql := &#039;SELECT &#039; &#124;&#124; v_chr_sql &#124;&#124; &#039; FROM powerseller.loan L, powerseller.gmacm_loan_search B&#039;
			&#124;&#124; &#039; WHERE L.servicing_number = B.servicing_number&#039;
			&#124;&#124; &#039; AND B.pool_name IN (SELECT column_value pool_name FROM THE&#039;
			&#124;&#124; &#039; (SELECT CAST(in_list_fnc(UPPER(&#039;&#039;&#039; &#124;&#124; pi_pool_id_list &#124;&#124; &#039;&#039;&#039;)) AS ListTableType) FROM DUAL))&#039;
			&#124;&#124; &#039; ORDER BY L.pool_name, L.servicing_number&#039;;
  dbms_output.put_line(v_chr_sql);
      OPEN pio_cstdn_extract_cur FOR v_chr_sql;]]></description>
		<content:encoded><![CDATA[<p>I have to set a Cron job to run the package/procedure on a daily basis.<br />
Within the procedure , I have a ref cursor and i need to convert the data into a CSV or excel file . This proc will be called in a cron job and the output file will be placed in some folder within server or networl Drive , Please help</p>
<p>Expample<br />
		v_chr_sql := &#8216;SELECT &#8216; || v_chr_sql || &#8216; FROM powerseller.loan L, powerseller.gmacm_loan_search B&#8217;<br />
			|| &#8216; WHERE L.servicing_number = B.servicing_number&#8217;<br />
			|| &#8216; AND B.pool_name IN (SELECT column_value pool_name FROM THE&#8217;<br />
			|| &#8216; (SELECT CAST(in_list_fnc(UPPER(&#8221;&#8217; || pi_pool_id_list || &#8221;&#8217;)) AS ListTableType) FROM DUAL))&#8217;<br />
			|| &#8216; ORDER BY L.pool_name, L.servicing_number&#8217;;<br />
  dbms_output.put_line(v_chr_sql);<br />
      OPEN pio_cstdn_extract_cur FOR v_chr_sql;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: mikesmithers</title>
		<link>http://mikesmithers.wordpress.com/2010/09/13/getting-output-from-ref-cursors-in-plsql/#comment-1617</link>
		<dc:creator><![CDATA[mikesmithers]]></dc:creator>
		<pubDate>Thu, 30 Dec 2010 13:45:31 +0000</pubDate>
		<guid isPermaLink="false">http://mikesmithers.wordpress.com/?p=571#comment-1617</guid>
		<description><![CDATA[Oh that Tom Kyte - he&#039;s such a clever clogs. He really should write a book :-)
On a slightly more serious note, when you run this code, the output you get is XML...
[sourcecode light=&quot;true&quot;]
&lt;?xml version=&quot;1.0&quot;?&gt;
&lt;ROWSET&gt;
&lt;ROW&gt;
&lt;NAME&gt;HART&lt;/NAME&gt;
&lt;POSITION&gt;GOALKEEPER&lt;/POSITION&gt;
&lt;CAPS&gt;6&lt;/CAPS&gt;
&lt;GOALS&gt;0&lt;/GOALS&gt;
&lt;/ROW&gt;
&lt;ROW&gt;
&lt;NAME&gt;CARSON&lt;/NAME&gt;
&lt;POSITION&gt;GOALKEEPER&lt;/POSITION&gt;
&lt;CAPS&gt;3&lt;/CAPS&gt;
&lt;GOALS&gt;0&lt;/GOALS&gt;
&lt;/ROW&gt;
&lt;ROW&gt;
&lt;NAME&gt;FOSTER&lt;/NAME&gt;
&lt;POSITION&gt;GOALKEEPER&lt;/POSITION&gt;
&lt;CAPS&gt;4&lt;/CAPS&gt;
&lt;GOALS&gt;0&lt;/GOALS&gt;
&lt;/ROW&gt;
&lt;ROW&gt;
&lt;NAME&gt;CAHILL&lt;/NAME&gt;
&lt;POSITION&gt;DEFENDER&lt;/POSITION&gt;
&lt;CAPS&gt;1&lt;/CAPS&gt;
&lt;GOALS&gt;0&lt;/GOALS&gt;
&lt;/ROW&gt;
&lt;ROW&gt;
&lt;NAME&gt;COLE A&lt;/NAME&gt;
&lt;POSITION&gt;DEFENDER&lt;/POSITION&gt;
&lt;CAPS&gt;85&lt;/CAPS&gt;
&lt;GOALS&gt;0&lt;/GOALS&gt;
&lt;/ROW&gt;
&lt;ROW&gt;
&lt;NAME&gt;DAWSON&lt;/NAME&gt;
&lt;POSITION&gt;DEFENDER&lt;/POSITION&gt;
&lt;CAPS&gt;2&lt;/CAPS&gt;
&lt;GOALS&gt;0&lt;/GOALS&gt;
&lt;/ROW&gt;
&lt;ROW&gt;
&lt;NAME&gt;GIBBS&lt;/NAME&gt;
&lt;POSITION&gt;DEFENDER&lt;/POSITION&gt;
&lt;CAPS&gt;1&lt;/CAPS&gt;
&lt;GOALS&gt;0&lt;/GOALS&gt;
&lt;/ROW&gt;
&lt;ROW&gt;
&lt;NAME&gt;JAGIELKA&lt;/NAME&gt;
&lt;POSITION&gt;DEFENDER&lt;/POSITION&gt;
&lt;CAPS&gt;6&lt;/CAPS&gt;
&lt;GOALS&gt;0&lt;/GOALS&gt;
&lt;/ROW&gt;
&lt;ROW&gt;
&lt;NAME&gt;JOHNSON G&lt;/NAME&gt;
&lt;POSITION&gt;DEFENDER&lt;/POSITION&gt;
&lt;CAPS&gt;29&lt;/CAPS&gt;
&lt;GOALS&gt;1&lt;/GOALS&gt;
&lt;/ROW&gt;
&lt;ROW&gt;
&lt;NAME&gt;LESCOTT&lt;/NAME&gt;
&lt;POSITION&gt;DEFENDER&lt;/POSITION&gt;
&lt;CAPS&gt;10&lt;/CAPS&gt;
&lt;GOALS&gt;0&lt;/GOALS&gt;
&lt;/ROW&gt;
&lt;ROW&gt;
&lt;NAME&gt;UPSON&lt;/NAME&gt;
&lt;POSITION&gt;DEFENDER&lt;/POSITION&gt;
&lt;CAPS&gt;21&lt;/CAPS&gt;
&lt;GOALS&gt;2&lt;/GOALS&gt;
&lt;/ROW&gt;
&lt;ROW&gt;
&lt;NAME&gt;BARRY&lt;/NAME&gt;
&lt;POSITION&gt;MIDFIELDER&lt;/POSITION&gt;
&lt;CAPS&gt;42&lt;/CAPS&gt;
&lt;GOALS&gt;2&lt;/GOALS&gt;
&lt;/ROW&gt;
&lt;ROW&gt;
&lt;NAME&gt;CARRICK&lt;/NAME&gt;
&lt;POSITION&gt;MIDFIELDER&lt;/POSITION&gt;
&lt;CAPS&gt;22&lt;/CAPS&gt;
&lt;GOALS&gt;0&lt;/GOALS&gt;
&lt;/ROW&gt;
&lt;ROW&gt;
&lt;NAME&gt;GERRARD&lt;/NAME&gt;
&lt;POSITION&gt;MIDFIELDER&lt;/POSITION&gt;
&lt;CAPS&gt;87&lt;/CAPS&gt;
&lt;GOALS&gt;19&lt;/GOALS&gt;
&lt;/ROW&gt;
&lt;ROW&gt;
&lt;NAME&gt;JOHNSON A&lt;/NAME&gt;
&lt;POSITION&gt;MIDFIELDER&lt;/POSITION&gt;
&lt;CAPS&gt;4&lt;/CAPS&gt;
&lt;GOALS&gt;2&lt;/GOALS&gt;
&lt;/ROW&gt;
&lt;ROW&gt;
&lt;NAME&gt;MILNER&lt;/NAME&gt;
&lt;POSITION&gt;MIDFIELDER&lt;/POSITION&gt;
&lt;CAPS&gt;14&lt;/CAPS&gt;
&lt;GOALS&gt;0&lt;/GOALS&gt;
&lt;/ROW&gt;
&lt;ROW&gt;
&lt;NAME&gt;WALCOTT&lt;/NAME&gt;
&lt;POSITION&gt;MIDFIELDER&lt;/POSITION&gt;
&lt;CAPS&gt;14&lt;/CAPS&gt;
&lt;GOALS&gt;3&lt;/GOALS&gt;
&lt;/ROW&gt;
&lt;ROW&gt;
&lt;NAME&gt;WRIGHT-PHILLIPS&lt;/NAME&gt;
&lt;POSITION&gt;MIDFIELDER&lt;/POSITION&gt;
&lt;CAPS&gt;35&lt;/CAPS&gt;
&lt;GOALS&gt;6&lt;/GOALS&gt;
&lt;/ROW&gt;
&lt;ROW&gt;
&lt;NAME&gt;YOUNG&lt;/NAME&gt;
&lt;POSITION&gt;MIDFIELDER&lt;/POSITION&gt;
&lt;CAPS&gt;9&lt;/CAPS&gt;
&lt;GOALS&gt;0&lt;/GOALS&gt;
&lt;/ROW&gt;
&lt;ROW&gt;
&lt;NAME&gt;BENT&lt;/NAME&gt;
&lt;POSITION&gt;STRIKER&lt;/POSITION&gt;
&lt;CAPS&gt;7&lt;/CAPS&gt;
&lt;GOALS&gt;1&lt;/GOALS&gt;
&lt;/ROW&gt;
&lt;ROW&gt;
&lt;NAME&gt;COLE C&lt;/NAME&gt;
&lt;POSITION&gt;STRIKER&lt;/POSITION&gt;
&lt;CAPS&gt;7&lt;/CAPS&gt;
&lt;GOALS&gt;0&lt;/GOALS&gt;
&lt;/ROW&gt;
&lt;ROW&gt;
&lt;NAME&gt;CROUCH&lt;/NAME&gt;
&lt;POSITION&gt;STRIKER&lt;/POSITION&gt;
&lt;CAPS&gt;40&lt;/CAPS&gt;
&lt;GOALS&gt;21&lt;/GOALS&gt;
&lt;/ROW&gt;
&lt;ROW&gt;
&lt;NAME&gt;DEFOE&lt;/NAME&gt;
&lt;POSITION&gt;STRIKER&lt;/POSITION&gt;
&lt;CAPS&gt;45&lt;/CAPS&gt;
&lt;GOALS&gt;15&lt;/GOALS&gt;
&lt;/ROW&gt;
&lt;ROW&gt;
&lt;NAME&gt;ROONEY&lt;/NAME&gt;
&lt;POSITION&gt;STRIKER&lt;/POSITION&gt;
&lt;CAPS&gt;67&lt;/CAPS&gt;
&lt;GOALS&gt;26&lt;/GOALS&gt;
&lt;/ROW&gt;
&lt;/ROWSET&gt;

PL/SQL procedure successfully completed.

SQL&gt; 
[/sourcecode]

This is slightly different to the starting point for this post, which was getting output in a CSV format. However, I&#039;m sure there are people reading this who will find that it&#039;s just what they&#039;re looking for.
Thanks for sharing,

Mike]]></description>
		<content:encoded><![CDATA[<p>Oh that Tom Kyte &#8211; he&#8217;s such a clever clogs. He really should write a book <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /><br />
On a slightly more serious note, when you run this code, the output you get is XML&#8230;</p>
<pre class="brush: plain; light: true; title: ; notranslate">
&lt;?xml version=&quot;1.0&quot;?&gt;
&lt;ROWSET&gt;
&lt;ROW&gt;
&lt;NAME&gt;HART&lt;/NAME&gt;
&lt;POSITION&gt;GOALKEEPER&lt;/POSITION&gt;
&lt;CAPS&gt;6&lt;/CAPS&gt;
&lt;GOALS&gt;0&lt;/GOALS&gt;
&lt;/ROW&gt;
&lt;ROW&gt;
&lt;NAME&gt;CARSON&lt;/NAME&gt;
&lt;POSITION&gt;GOALKEEPER&lt;/POSITION&gt;
&lt;CAPS&gt;3&lt;/CAPS&gt;
&lt;GOALS&gt;0&lt;/GOALS&gt;
&lt;/ROW&gt;
&lt;ROW&gt;
&lt;NAME&gt;FOSTER&lt;/NAME&gt;
&lt;POSITION&gt;GOALKEEPER&lt;/POSITION&gt;
&lt;CAPS&gt;4&lt;/CAPS&gt;
&lt;GOALS&gt;0&lt;/GOALS&gt;
&lt;/ROW&gt;
&lt;ROW&gt;
&lt;NAME&gt;CAHILL&lt;/NAME&gt;
&lt;POSITION&gt;DEFENDER&lt;/POSITION&gt;
&lt;CAPS&gt;1&lt;/CAPS&gt;
&lt;GOALS&gt;0&lt;/GOALS&gt;
&lt;/ROW&gt;
&lt;ROW&gt;
&lt;NAME&gt;COLE A&lt;/NAME&gt;
&lt;POSITION&gt;DEFENDER&lt;/POSITION&gt;
&lt;CAPS&gt;85&lt;/CAPS&gt;
&lt;GOALS&gt;0&lt;/GOALS&gt;
&lt;/ROW&gt;
&lt;ROW&gt;
&lt;NAME&gt;DAWSON&lt;/NAME&gt;
&lt;POSITION&gt;DEFENDER&lt;/POSITION&gt;
&lt;CAPS&gt;2&lt;/CAPS&gt;
&lt;GOALS&gt;0&lt;/GOALS&gt;
&lt;/ROW&gt;
&lt;ROW&gt;
&lt;NAME&gt;GIBBS&lt;/NAME&gt;
&lt;POSITION&gt;DEFENDER&lt;/POSITION&gt;
&lt;CAPS&gt;1&lt;/CAPS&gt;
&lt;GOALS&gt;0&lt;/GOALS&gt;
&lt;/ROW&gt;
&lt;ROW&gt;
&lt;NAME&gt;JAGIELKA&lt;/NAME&gt;
&lt;POSITION&gt;DEFENDER&lt;/POSITION&gt;
&lt;CAPS&gt;6&lt;/CAPS&gt;
&lt;GOALS&gt;0&lt;/GOALS&gt;
&lt;/ROW&gt;
&lt;ROW&gt;
&lt;NAME&gt;JOHNSON G&lt;/NAME&gt;
&lt;POSITION&gt;DEFENDER&lt;/POSITION&gt;
&lt;CAPS&gt;29&lt;/CAPS&gt;
&lt;GOALS&gt;1&lt;/GOALS&gt;
&lt;/ROW&gt;
&lt;ROW&gt;
&lt;NAME&gt;LESCOTT&lt;/NAME&gt;
&lt;POSITION&gt;DEFENDER&lt;/POSITION&gt;
&lt;CAPS&gt;10&lt;/CAPS&gt;
&lt;GOALS&gt;0&lt;/GOALS&gt;
&lt;/ROW&gt;
&lt;ROW&gt;
&lt;NAME&gt;UPSON&lt;/NAME&gt;
&lt;POSITION&gt;DEFENDER&lt;/POSITION&gt;
&lt;CAPS&gt;21&lt;/CAPS&gt;
&lt;GOALS&gt;2&lt;/GOALS&gt;
&lt;/ROW&gt;
&lt;ROW&gt;
&lt;NAME&gt;BARRY&lt;/NAME&gt;
&lt;POSITION&gt;MIDFIELDER&lt;/POSITION&gt;
&lt;CAPS&gt;42&lt;/CAPS&gt;
&lt;GOALS&gt;2&lt;/GOALS&gt;
&lt;/ROW&gt;
&lt;ROW&gt;
&lt;NAME&gt;CARRICK&lt;/NAME&gt;
&lt;POSITION&gt;MIDFIELDER&lt;/POSITION&gt;
&lt;CAPS&gt;22&lt;/CAPS&gt;
&lt;GOALS&gt;0&lt;/GOALS&gt;
&lt;/ROW&gt;
&lt;ROW&gt;
&lt;NAME&gt;GERRARD&lt;/NAME&gt;
&lt;POSITION&gt;MIDFIELDER&lt;/POSITION&gt;
&lt;CAPS&gt;87&lt;/CAPS&gt;
&lt;GOALS&gt;19&lt;/GOALS&gt;
&lt;/ROW&gt;
&lt;ROW&gt;
&lt;NAME&gt;JOHNSON A&lt;/NAME&gt;
&lt;POSITION&gt;MIDFIELDER&lt;/POSITION&gt;
&lt;CAPS&gt;4&lt;/CAPS&gt;
&lt;GOALS&gt;2&lt;/GOALS&gt;
&lt;/ROW&gt;
&lt;ROW&gt;
&lt;NAME&gt;MILNER&lt;/NAME&gt;
&lt;POSITION&gt;MIDFIELDER&lt;/POSITION&gt;
&lt;CAPS&gt;14&lt;/CAPS&gt;
&lt;GOALS&gt;0&lt;/GOALS&gt;
&lt;/ROW&gt;
&lt;ROW&gt;
&lt;NAME&gt;WALCOTT&lt;/NAME&gt;
&lt;POSITION&gt;MIDFIELDER&lt;/POSITION&gt;
&lt;CAPS&gt;14&lt;/CAPS&gt;
&lt;GOALS&gt;3&lt;/GOALS&gt;
&lt;/ROW&gt;
&lt;ROW&gt;
&lt;NAME&gt;WRIGHT-PHILLIPS&lt;/NAME&gt;
&lt;POSITION&gt;MIDFIELDER&lt;/POSITION&gt;
&lt;CAPS&gt;35&lt;/CAPS&gt;
&lt;GOALS&gt;6&lt;/GOALS&gt;
&lt;/ROW&gt;
&lt;ROW&gt;
&lt;NAME&gt;YOUNG&lt;/NAME&gt;
&lt;POSITION&gt;MIDFIELDER&lt;/POSITION&gt;
&lt;CAPS&gt;9&lt;/CAPS&gt;
&lt;GOALS&gt;0&lt;/GOALS&gt;
&lt;/ROW&gt;
&lt;ROW&gt;
&lt;NAME&gt;BENT&lt;/NAME&gt;
&lt;POSITION&gt;STRIKER&lt;/POSITION&gt;
&lt;CAPS&gt;7&lt;/CAPS&gt;
&lt;GOALS&gt;1&lt;/GOALS&gt;
&lt;/ROW&gt;
&lt;ROW&gt;
&lt;NAME&gt;COLE C&lt;/NAME&gt;
&lt;POSITION&gt;STRIKER&lt;/POSITION&gt;
&lt;CAPS&gt;7&lt;/CAPS&gt;
&lt;GOALS&gt;0&lt;/GOALS&gt;
&lt;/ROW&gt;
&lt;ROW&gt;
&lt;NAME&gt;CROUCH&lt;/NAME&gt;
&lt;POSITION&gt;STRIKER&lt;/POSITION&gt;
&lt;CAPS&gt;40&lt;/CAPS&gt;
&lt;GOALS&gt;21&lt;/GOALS&gt;
&lt;/ROW&gt;
&lt;ROW&gt;
&lt;NAME&gt;DEFOE&lt;/NAME&gt;
&lt;POSITION&gt;STRIKER&lt;/POSITION&gt;
&lt;CAPS&gt;45&lt;/CAPS&gt;
&lt;GOALS&gt;15&lt;/GOALS&gt;
&lt;/ROW&gt;
&lt;ROW&gt;
&lt;NAME&gt;ROONEY&lt;/NAME&gt;
&lt;POSITION&gt;STRIKER&lt;/POSITION&gt;
&lt;CAPS&gt;67&lt;/CAPS&gt;
&lt;GOALS&gt;26&lt;/GOALS&gt;
&lt;/ROW&gt;
&lt;/ROWSET&gt;

PL/SQL procedure successfully completed.

SQL&gt; 
</pre>
<p>This is slightly different to the starting point for this post, which was getting output in a CSV format. However, I&#8217;m sure there are people reading this who will find that it&#8217;s just what they&#8217;re looking for.<br />
Thanks for sharing,</p>
<p>Mike</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: david</title>
		<link>http://mikesmithers.wordpress.com/2010/09/13/getting-output-from-ref-cursors-in-plsql/#comment-1613</link>
		<dc:creator><![CDATA[david]]></dc:creator>
		<pubDate>Thu, 30 Dec 2010 08:21:49 +0000</pubDate>
		<guid isPermaLink="false">http://mikesmithers.wordpress.com/?p=571#comment-1613</guid>
		<description><![CDATA[here is someone&#039;s code on Tkyte :D

declare
  cur sys_refcursor;

  procedure p(p_str in varchar2) is
    l_str   long := p_str &#124;&#124; chr(10);
    l_piece long;
    n       number;
  begin
    loop
      exit when l_str is null;
      n       := instr(l_str, chr(10));
      l_piece := substr(l_str, 1, n - 1);
      l_str   := substr(l_str, n + 1);
      loop
        exit when l_piece is null;
        dbms_output.put_line(substr(l_piece, 1, 250));
        l_piece := substr(l_piece, 251);
      end loop;
    end loop;
  end;

  function print_refcursor(cur sys_refcursor) return varchar2 as
  begin
    return xmltype(cur).getstringval();
  end print_refcursor;
  
begin
  open cur for
    select * from tab;

  p(print_refcursor(cur));
end;
/]]></description>
		<content:encoded><![CDATA[<p>here is someone&#8217;s code on Tkyte <img src='http://s0.wp.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<p>declare<br />
  cur sys_refcursor;</p>
<p>  procedure p(p_str in varchar2) is<br />
    l_str   long := p_str || chr(10);<br />
    l_piece long;<br />
    n       number;<br />
  begin<br />
    loop<br />
      exit when l_str is null;<br />
      n       := instr(l_str, chr(10));<br />
      l_piece := substr(l_str, 1, n &#8211; 1);<br />
      l_str   := substr(l_str, n + 1);<br />
      loop<br />
        exit when l_piece is null;<br />
        dbms_output.put_line(substr(l_piece, 1, 250));<br />
        l_piece := substr(l_piece, 251);<br />
      end loop;<br />
    end loop;<br />
  end;</p>
<p>  function print_refcursor(cur sys_refcursor) return varchar2 as<br />
  begin<br />
    return xmltype(cur).getstringval();<br />
  end print_refcursor;</p>
<p>begin<br />
  open cur for<br />
    select * from tab;</p>
<p>  p(print_refcursor(cur));<br />
end;<br />
/</p>
]]></content:encoded>
	</item>
</channel>
</rss>
