<?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"
	>
<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>
	<pubDate>Wed, 09 Jul 2008 00:43:32 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5</generator>
		<item>
		<title>By: Michael Moore</title>
		<link>http://awads.net/wp/2007/04/10/no_data_found-gotcha/#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 " too_many_rows - if the query actualy succeedsâ€¦."&lt;/p&gt;

&lt;p&gt;I took off the "1 =0"  and it ran with no problem.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Simon,<br />
what do you mean by &#8221; too_many_rows - 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-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-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'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 :<br />
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 - 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-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&#62; 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 ('RESULT = '&#124;&#124;l_count);
 10  EXCEPTION
 11    when NO_DATA_FOUND then
 12      DBMS_OUTPUT.put_line ('Query returned no data!');
 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 :<br />
if you add a group by clause to the query, e.g.,<br />
SQL&gt; DECLARE<br />
  2    l_count number;<br />
  3  BEGIN<br />
  4    select count()<br />
  5    into l_count<br />
  6    from all_objects<br />
  7    where 1 =0<br />
  8    group by 1;<br />
  9    DBMS_OUTPUT.put_line (&#8217;RESULT = &#8216;||l_count);<br />
 10  EXCEPTION<br />
 11    when NO_DATA_FOUND then<br />
 12      DBMS_OUTPUT.put_line (&#8217;Query returned no data!&#8217;);<br />
 13  END;<br />
 14  /<br />
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-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<br />
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-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), 'DEFAULT_VALUE') into l_foo from table_name where x='BLAH';&lt;/p&gt;

&lt;p&gt;In this case when there is no value I set a default and don'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-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 "gotcha" 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 "data is found".&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-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'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&#62;create table js ( x integer);&lt;/p&gt;

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

&lt;p&gt;SQL&#62;
SQL&#62;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;<br />
SQL&gt;declare<br />
  2          v_x integer;<br />
  3  begin<br />
  4          select count(*) into v_x from js;<br />
  5          dbms_output.put_line(v_x);<br />
  6  end;<br />
  7  /<br />
0</p>
<p>PL/SQL procedure successfully completed.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
