<?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:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: NO_DATA_FOUND Gotcha</title>
	<atom:link href="http://awads.net/wp/2007/04/10/no_data_found-gotcha/feed/" rel="self" type="application/rss+xml" />
	<link>http://awads.net/wp/2007/04/10/no_data_found-gotcha/</link>
	<description>News, views, tips and tricks on Oracle and other fun stuff</description>
	<lastBuildDate>Tue, 24 Jan 2012 20:49:08 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Michael Moore</title>
		<link>http://awads.net/wp/2007/04/10/no_data_found-gotcha/comment-page-1/#comment-50775</link>
		<dc:creator>Michael Moore</dc:creator>
		<pubDate>Mon, 14 May 2007 23:20:35 +0000</pubDate>
		<guid isPermaLink="false">http://awads.net/wp/2007/04/10/no_data_found-gotcha/#comment-50775</guid>
		<description>&lt;p&gt;Simon, 
what do you mean by &quot; too_many_rows - if the query actualy succeedsâ€¦.&quot;&lt;/p&gt;

&lt;p&gt;I took off the &quot;1 =0&quot;  and it ran with no problem.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Simon, 
what do you mean by &#8221; too_many_rows &#8211; if the query actualy succeedsâ€¦.&#8221;</p>

<p>I took off the &#8220;1 =0&#8243;  and it ran with no problem.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Karl</title>
		<link>http://awads.net/wp/2007/04/10/no_data_found-gotcha/comment-page-1/#comment-50747</link>
		<dc:creator>Karl</dc:creator>
		<pubDate>Tue, 08 May 2007 05:27:13 +0000</pubDate>
		<guid isPermaLink="false">http://awads.net/wp/2007/04/10/no_data_found-gotcha/#comment-50747</guid>
		<description>&lt;p&gt;Raising NO_DATA_FOUND on subscription error. It seems the developers were not busy enough to create an own out_of_bound exception for it&lt;/p&gt;

&lt;p&gt;Karl&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Raising NO_DATA_FOUND on subscription error. It seems the developers were not busy enough to create an own out_of_bound exception for it</p>

<p>Karl</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Simon</title>
		<link>http://awads.net/wp/2007/04/10/no_data_found-gotcha/comment-page-1/#comment-50500</link>
		<dc:creator>Simon</dc:creator>
		<pubDate>Mon, 16 Apr 2007 14:13:31 +0000</pubDate>
		<guid isPermaLink="false">http://awads.net/wp/2007/04/10/no_data_found-gotcha/#comment-50500</guid>
		<description>&lt;p&gt;Follow Up my own comment : 
I&#039;d like to note that in case of adding a group by clause to such a query, you should also deal with a possibility of too_many_rows - if the query actualy succeeds....&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Follow Up my own comment : 
I&#8217;d like to note that in case of adding a group by clause to such a query, you should also deal with a possibility of too_many_rows &#8211; if the query actualy succeeds&#8230;.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Simon</title>
		<link>http://awads.net/wp/2007/04/10/no_data_found-gotcha/comment-page-1/#comment-50499</link>
		<dc:creator>Simon</dc:creator>
		<pubDate>Mon, 16 Apr 2007 14:10:12 +0000</pubDate>
		<guid isPermaLink="false">http://awads.net/wp/2007/04/10/no_data_found-gotcha/#comment-50499</guid>
		<description>&lt;p&gt;Actualy there is a way to cause a COUNT() query to raise the NO_DATA_FOUND exception :
if you add a group by clause to the query, e.g., 
SQL&gt; DECLARE
  2    l_count number;
  3  BEGIN
  4    select count()
  5    into l_count
  6    from all_objects
  7    where 1 =0
  8    group by 1;
  9    DBMS_OUTPUT.put_line (&#039;RESULT = &#039;&#124;&#124;l_count);
 10  EXCEPTION
 11    when NO_DATA_FOUND then
 12      DBMS_OUTPUT.put_line (&#039;Query returned no data!&#039;);
 13  END;
 14  /
Query returned no data!&lt;/p&gt;

&lt;p&gt;PL/SQL procedure successfully completed&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Actualy there is a way to cause a COUNT() query to raise the NO_DATA_FOUND exception :
if you add a group by clause to the query, e.g., 
SQL&gt; DECLARE
  2    l_count number;
  3  BEGIN
  4    select count()
  5    into l_count
  6    from all_objects
  7    where 1 =0
  8    group by 1;
  9    DBMS_OUTPUT.put_line (&#8216;RESULT = &#8216;||l_count);
 10  EXCEPTION
 11    when NO_DATA_FOUND then
 12      DBMS_OUTPUT.put_line (&#8216;Query returned no data!&#8217;);
 13  END;
 14  /
Query returned no data!</p>

<p>PL/SQL procedure successfully completed</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Jared</title>
		<link>http://awads.net/wp/2007/04/10/no_data_found-gotcha/comment-page-1/#comment-50491</link>
		<dc:creator>Jared</dc:creator>
		<pubDate>Wed, 11 Apr 2007 20:43:55 +0000</pubDate>
		<guid isPermaLink="false">http://awads.net/wp/2007/04/10/no_data_found-gotcha/#comment-50491</guid>
		<description>&lt;p&gt;Using nvl() ensures that your query will retrieve a non-null value.&lt;/p&gt;

&lt;p&gt;It does not prevent any error condition though, as there would not be on.&lt;/p&gt;

&lt;p&gt;select max(x) from js
where js is an empty table will not raise an error.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Using nvl() ensures that your query will retrieve a non-null value.</p>

<p>It does not prevent any error condition though, as there would not be on.</p>

<p>select max(x) from js
where js is an empty table will not raise an error.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Ethan</title>
		<link>http://awads.net/wp/2007/04/10/no_data_found-gotcha/comment-page-1/#comment-50490</link>
		<dc:creator>Ethan</dc:creator>
		<pubDate>Wed, 11 Apr 2007 20:35:25 +0000</pubDate>
		<guid isPermaLink="false">http://awads.net/wp/2007/04/10/no_data_found-gotcha/#comment-50490</guid>
		<description>&lt;p&gt;I often do this sort of thing...&lt;/p&gt;

&lt;p&gt;select nvl(max(col), &#039;DEFAULT_VALUE&#039;) into l_foo from table_name where x=&#039;BLAH&#039;;&lt;/p&gt;

&lt;p&gt;In this case when there is no value I set a default and don&#039;t get the error. In the event that there is more than one value I only get one (I usually only implement this when that is very unlikely).&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Ethan&lt;/li&gt;
&lt;/ul&gt;
</description>
		<content:encoded><![CDATA[<p>I often do this sort of thing&#8230;</p>

<p>select nvl(max(col), &#8216;DEFAULT_VALUE&#8217;) into l_foo from table_name where x=&#8217;BLAH&#8217;;</p>

<p>In this case when there is no value I set a default and don&#8217;t get the error. In the event that there is more than one value I only get one (I usually only implement this when that is very unlikely).</p>

<ul>
<li>Ethan</li>
</ul>]]></content:encoded>
	</item>
	<item>
		<title>By: Eddie Awad</title>
		<link>http://awads.net/wp/2007/04/10/no_data_found-gotcha/comment-page-1/#comment-50489</link>
		<dc:creator>Eddie Awad</dc:creator>
		<pubDate>Wed, 11 Apr 2007 17:19:46 +0000</pubDate>
		<guid isPermaLink="false">http://awads.net/wp/2007/04/10/no_data_found-gotcha/#comment-50489</guid>
		<description>&lt;p&gt;Thanks Jared. I have been bitten with this &quot;gotcha&quot; when I first started with PL/SQL. Then, I learned that  a SELECT INTO statement that calls a SQL aggregate function, such as COUNT(*) or AVG(), always returns a value or a null. Aggregate functions are guaranteed to return a single value, even if no &quot;data is found&quot;.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Thanks Jared. I have been bitten with this &#8220;gotcha&#8221; when I first started with PL/SQL. Then, I learned that  a SELECT INTO statement that calls a SQL aggregate function, such as COUNT(*) or AVG(), always returns a value or a null. Aggregate functions are guaranteed to return a single value, even if no &#8220;data is found&#8221;.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Jared</title>
		<link>http://awads.net/wp/2007/04/10/no_data_found-gotcha/comment-page-1/#comment-50488</link>
		<dc:creator>Jared</dc:creator>
		<pubDate>Wed, 11 Apr 2007 16:52:46 +0000</pubDate>
		<guid isPermaLink="false">http://awads.net/wp/2007/04/10/no_data_found-gotcha/#comment-50488</guid>
		<description>&lt;p&gt;Here&#039;s one that has probably bitten a few people.&lt;/p&gt;

&lt;p&gt;The count() function does not raise a no_data_found error when no rows are returned, even when the table is empty.&lt;/p&gt;

&lt;p&gt;SQL&gt;create table js ( x integer);&lt;/p&gt;

&lt;p&gt;Table created.&lt;/p&gt;

&lt;p&gt;SQL&gt;
SQL&gt;declare
  2          v_x integer;
  3  begin
  4          select count(*) into v_x from js;
  5          dbms_output.put_line(v_x);
  6  end;
  7  /
0&lt;/p&gt;

&lt;p&gt;PL/SQL procedure successfully completed.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Here&#8217;s one that has probably bitten a few people.</p>

<p>The count() function does not raise a no_data_found error when no rows are returned, even when the table is empty.</p>

<p>SQL&gt;create table js ( x integer);</p>

<p>Table created.</p>

<p>SQL&gt;
SQL&gt;declare
  2          v_x integer;
  3  begin
  4          select count(*) into v_x from js;
  5          dbms_output.put_line(v_x);
  6  end;
  7  /
0</p>

<p>PL/SQL procedure successfully completed.</p>]]></content:encoded>
	</item>
</channel>
</rss>

