<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title>Eddie Awad’s Blog - Latest Comments in NO_DATA_FOUND Gotcha</title><link>http://awads.disqus.com/</link><description>News, views, tips and tricks on Oracle and other fun stuff</description><atom:link href="https://awads.disqus.com/no_data_found_gotcha/latest.rss" rel="self"></atom:link><language>en</language><lastBuildDate>Mon, 14 May 2007 19:20:35 -0000</lastBuildDate><item><title>Re: NO_DATA_FOUND Gotcha</title><link>http://awads.net/wp/2007/04/10/no_data_found-gotcha/#comment-3659110</link><description>&lt;p&gt;Simon, &lt;br&gt;what do you mean by " too_many_rows - if the query actualy succeedsâ€¦."&lt;/p&gt;&lt;p&gt;&lt;br&gt;&lt;/p&gt;&lt;p&gt;I took off the "1 =0"  and it ran with no problem.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Michael Moore</dc:creator><pubDate>Mon, 14 May 2007 19:20:35 -0000</pubDate></item><item><title>Re: NO_DATA_FOUND Gotcha</title><link>http://awads.net/wp/2007/04/10/no_data_found-gotcha/#comment-3659109</link><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;&lt;br&gt;&lt;/p&gt;&lt;p&gt;Karl&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Karl</dc:creator><pubDate>Tue, 08 May 2007 01:27:13 -0000</pubDate></item><item><title>Re: NO_DATA_FOUND Gotcha</title><link>http://awads.net/wp/2007/04/10/no_data_found-gotcha/#comment-3659108</link><description>&lt;p&gt;Follow Up my own comment : &lt;br&gt;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><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Simon</dc:creator><pubDate>Mon, 16 Apr 2007 10:13:31 -0000</pubDate></item><item><title>Re: NO_DATA_FOUND Gotcha</title><link>http://awads.net/wp/2007/04/10/no_data_found-gotcha/#comment-3659107</link><description>&lt;p&gt;Actualy there is a way to cause a COUNT() query to raise the NO_DATA_FOUND exception :&lt;br&gt;if you add a group by clause to the query, e.g., &lt;br&gt;SQL&amp;gt; DECLARE&lt;br&gt;  2    l_count number;&lt;br&gt;  3  BEGIN&lt;br&gt;  4    select count()&lt;br&gt;  5    into l_count&lt;br&gt;  6    from all_objects&lt;br&gt;  7    where 1 =0&lt;br&gt;  8    group by 1;&lt;br&gt;  9    DBMS_OUTPUT.put_line ('RESULT = '||l_count);&lt;br&gt; 10  EXCEPTION&lt;br&gt; 11    when NO_DATA_FOUND then&lt;br&gt; 12      DBMS_OUTPUT.put_line ('Query returned no data!');&lt;br&gt; 13  END;&lt;br&gt; 14  /&lt;br&gt;Query returned no data!&lt;/p&gt;&lt;p&gt;&lt;br&gt;&lt;/p&gt;&lt;p&gt;PL/SQL procedure successfully completed&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Simon</dc:creator><pubDate>Mon, 16 Apr 2007 10:10:12 -0000</pubDate></item><item><title>Re: NO_DATA_FOUND Gotcha</title><link>http://awads.net/wp/2007/04/10/no_data_found-gotcha/#comment-3659106</link><description>&lt;p&gt;Using nvl() ensures that your query will retrieve a non-null value.&lt;/p&gt;&lt;p&gt;&lt;br&gt;&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;&lt;br&gt;&lt;/p&gt;&lt;p&gt;select max(x) from js&lt;br&gt;where js is an empty table will not raise an error.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Jared</dc:creator><pubDate>Wed, 11 Apr 2007 16:43:55 -0000</pubDate></item><item><title>Re: NO_DATA_FOUND Gotcha</title><link>http://awads.net/wp/2007/04/10/no_data_found-gotcha/#comment-3659105</link><description>&lt;p&gt;I often do this sort of thing...&lt;/p&gt;&lt;p&gt;&lt;br&gt;&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;&lt;br&gt;&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;p&gt;&lt;br&gt;&amp;lt;ul&amp;gt;&lt;br&gt;&amp;lt;li&amp;gt;Ethan&amp;lt;/li&amp;gt;&lt;br&gt;&amp;lt;/ul&amp;gt;&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Ethan</dc:creator><pubDate>Wed, 11 Apr 2007 16:35:25 -0000</pubDate></item><item><title>Re: NO_DATA_FOUND Gotcha</title><link>http://awads.net/wp/2007/04/10/no_data_found-gotcha/#comment-3659104</link><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><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Eddie Awad</dc:creator><pubDate>Wed, 11 Apr 2007 13:19:46 -0000</pubDate></item><item><title>Re: NO_DATA_FOUND Gotcha</title><link>http://awads.net/wp/2007/04/10/no_data_found-gotcha/#comment-3659103</link><description>&lt;p&gt;Here's one that has probably bitten a few people.&lt;/p&gt;&lt;p&gt;&lt;br&gt;&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;&lt;br&gt;&lt;/p&gt;&lt;p&gt;SQL&amp;gt;create table js ( x integer);&lt;/p&gt;&lt;p&gt;&lt;br&gt;&lt;/p&gt;&lt;p&gt;Table created.&lt;/p&gt;&lt;p&gt;&lt;br&gt;&lt;/p&gt;&lt;p&gt;SQL&amp;gt;&lt;br&gt;SQL&amp;gt;declare&lt;br&gt;  2          v_x integer;&lt;br&gt;  3  begin&lt;br&gt;  4          select count(*) into v_x from js;&lt;br&gt;  5          dbms_output.put_line(v_x);&lt;br&gt;  6  end;&lt;br&gt;  7  /&lt;br&gt;0&lt;/p&gt;&lt;p&gt;&lt;br&gt;&lt;/p&gt;&lt;p&gt;PL/SQL procedure successfully completed.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Jared</dc:creator><pubDate>Wed, 11 Apr 2007 12:52:46 -0000</pubDate></item></channel></rss>