<?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: &#9733; The order of conditions matters</title>
	<atom:link href="http://awads.net/wp/2006/03/03/the-order-of-conditions-matters/feed/" rel="self" type="application/rss+xml" />
	<link>http://awads.net/wp/2006/03/03/the-order-of-conditions-matters/</link>
	<description>News, views, tips and tricks on Oracle and other fun stuff</description>
	<lastBuildDate>Mon, 21 May 2012 00:26:47 -0700</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
	<item>
		<title>By: Steven Meyer</title>
		<link>http://awads.net/wp/2006/03/03/the-order-of-conditions-matters/comment-page-1/#comment-52231</link>
		<dc:creator>Steven Meyer</dc:creator>
		<pubDate>Wed, 30 Jul 2008 15:23:16 +0000</pubDate>
		<guid isPermaLink="false">http://awads.net/wp/?p=228#comment-52231</guid>
		<description>&lt;p&gt;Quote iG &quot;It is NOT ALWAYS guaranted...&quot; then iG goes on to show  an example in SQL.
But remember that the order of evaluation in SQL is not as written.&lt;/p&gt;

&lt;pre&gt;SQL&gt; CREATE OR REPLACE FUNCTION this_is_y(x NUMBER) RETURN VARCHAR2 IS
  2  BEGIN
  3    dbms_output.put_line(&#039;Inside function this_is_Y(&#039; &#124;&#124; x &#124;&#124; &#039;)&#039;);
  4    RETURN &#039;Y&#039;;
  5  END this_is_Y;
  6  /

Function created.

SQL&gt; CREATE OR REPLACE FUNCTION this_is_n(x NUMBER) RETURN VARCHAR2 IS
  2  BEGIN
  3    dbms_output.put_line(&#039;Inside function this_is_N(&#039; &#124;&#124; x &#124;&#124; &#039;)&#039;);
  4    RETURN &#039;N&#039;;
  5  END this_is_n;
  6  /

Function created.
&lt;/pre&gt;

&lt;pre&gt;
SQL&gt; SELECT *
  2  FROM   (SELECT object_id
  3          FROM   user_objects
  4          WHERE  9 &gt; rownum)
  5  WHERE  this_is_y(object_id) = &#039;Y&#039;
  6  AND    this_is_n(object_id) = &#039;Y&#039;;

no rows selected

SQL&gt;
&lt;/pre&gt;

&lt;p&gt;And the output is:&lt;/p&gt;

&lt;pre&gt;
Inside function this_is_N(174702)
Inside function this_is_N(592838)
Inside function this_is_N(592839)
Inside function this_is_N(592840)
Inside function this_is_N(592841)
Inside function this_is_N(592842)
Inside function this_is_N(592843)
Inside function this_is_N(592844)
&lt;/pre&gt;
</description>
		<content:encoded><![CDATA[<p>Quote iG &#8220;It is NOT ALWAYS guaranted&#8230;&#8221; then iG goes on to show  an example in SQL.
But remember that the order of evaluation in SQL is not as written.</p>

<pre>SQL&gt; CREATE OR REPLACE FUNCTION this_is_y(x NUMBER) RETURN VARCHAR2 IS
  2  BEGIN
  3    dbms_output.put_line('Inside function this_is_Y(' || x || ')');
  4    RETURN 'Y';
  5  END this_is_Y;
  6  /

Function created.

SQL&gt; CREATE OR REPLACE FUNCTION this_is_n(x NUMBER) RETURN VARCHAR2 IS
  2  BEGIN
  3    dbms_output.put_line('Inside function this_is_N(' || x || ')');
  4    RETURN 'N';
  5  END this_is_n;
  6  /

Function created.
</pre>

<pre>
SQL&gt; SELECT *
  2  FROM   (SELECT object_id
  3          FROM   user_objects
  4          WHERE  9 &gt; rownum)
  5  WHERE  this_is_y(object_id) = 'Y'
  6  AND    this_is_n(object_id) = 'Y';

no rows selected

SQL&gt;
</pre>

<p>And the output is:</p>

<pre>
Inside function this_is_N(174702)
Inside function this_is_N(592838)
Inside function this_is_N(592839)
Inside function this_is_N(592840)
Inside function this_is_N(592841)
Inside function this_is_N(592842)
Inside function this_is_N(592843)
Inside function this_is_N(592844)
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: iG</title>
		<link>http://awads.net/wp/2006/03/03/the-order-of-conditions-matters/comment-page-1/#comment-51372</link>
		<dc:creator>iG</dc:creator>
		<pubDate>Sat, 11 Aug 2007 14:04:51 +0000</pubDate>
		<guid isPermaLink="false">http://awads.net/wp/?p=228#comment-51372</guid>
		<description>&lt;p&gt;Its NOT ALWAYS guaranted the in&lt;/p&gt;

&lt;p&gt;select from my_table where cond1 and cond2;&lt;/p&gt;

&lt;p&gt;cond1 be first evaluated. For a query I was doing, a must use:&lt;/p&gt;

&lt;p&gt;select /*+ no_cpu_costing */ from my_table where cond1 and cond2;&lt;/p&gt;

&lt;p&gt;Look at&lt;/p&gt;

&lt;p&gt;http://www.dba-oracle.com/oracle_tips_optimizer_cost_model.htm&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Its NOT ALWAYS guaranted the in</p>

<p>select from my_table where cond1 and cond2;</p>

<p>cond1 be first evaluated. For a query I was doing, a must use:</p>

<p>select /*+ no_cpu_costing */ from my_table where cond1 and cond2;</p>

<p>Look at</p>

<p><a href="http://www.dba-oracle.com/oracle_tips_optimizer_cost_model.htm" rel="nofollow">http://www.dba-oracle.com/oracle_tips_optimizer_cost_model.htm</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gaza</title>
		<link>http://awads.net/wp/2006/03/03/the-order-of-conditions-matters/comment-page-1/#comment-51325</link>
		<dc:creator>Gaza</dc:creator>
		<pubDate>Thu, 26 Jul 2007 04:32:38 +0000</pubDate>
		<guid isPermaLink="false">http://awads.net/wp/?p=228#comment-51325</guid>
		<description>&lt;p&gt;If (and only if) this behaviour is a standard
in PLSQL, then one could argue that the
more concise code that can be written 
using this IS more maintainable. More
verbose code, especially if it requires the
setting up and initialisation of more 
unnecessary variables, can reduce the maintainability of that code!&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>If (and only if) this behaviour is a standard
in PLSQL, then one could argue that the
more concise code that can be written 
using this IS more maintainable. More
verbose code, especially if it requires the
setting up and initialisation of more 
unnecessary variables, can reduce the maintainability of that code!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Eddie Awad</title>
		<link>http://awads.net/wp/2006/03/03/the-order-of-conditions-matters/comment-page-1/#comment-1943</link>
		<dc:creator>Eddie Awad</dc:creator>
		<pubDate>Fri, 03 Mar 2006 19:51:02 +0000</pubDate>
		<guid isPermaLink="false">http://awads.net/wp/?p=228#comment-1943</guid>
		<description>&lt;p&gt;Good and valid points Rob. Thank you. Nevertheless, the short-circuit evaluation notion in PL/SQL is rather an interesting fact (as of 10gR2).&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Good and valid points Rob. Thank you. Nevertheless, the short-circuit evaluation notion in PL/SQL is rather an interesting fact (as of 10gR2).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Robert Vollman</title>
		<link>http://awads.net/wp/2006/03/03/the-order-of-conditions-matters/comment-page-1/#comment-1942</link>
		<dc:creator>Robert Vollman</dc:creator>
		<pubDate>Fri, 03 Mar 2006 18:19:21 +0000</pubDate>
		<guid isPermaLink="false">http://awads.net/wp/?p=228#comment-1942</guid>
		<description>&lt;p&gt;Interesting.  But is this behaviour dependable?  And, if so, will it remain like this in future versions?  And, even if it is, is that necessarily the best coding practise?  Especially since you can just do this:&lt;/p&gt;

&lt;p&gt;IF (2=1) THEN
     IF (IS_GREATER_FUNC(1,2)) THEN
          DBMS_OUTPUT.PUT_LINE(&#039;TRUE&#039;);
     ELSE DBMS_OUTPUT.PUT_LINE(&#039;FALSE&#039;);
     END IF;
ELSE DBMS_OUTPUT.PUT_LINE(&#039;FALSE&#039;);
END IF;&lt;/p&gt;

&lt;p&gt;That way, your intention (to only check the second case if the first case is true) is clear, and dependable.  Sure, it&#039;s more lines of code, but easier to maintain.&lt;/p&gt;

&lt;p&gt;Rob&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Interesting.  But is this behaviour dependable?  And, if so, will it remain like this in future versions?  And, even if it is, is that necessarily the best coding practise?  Especially since you can just do this:</p>

<p>IF (2=1) THEN
     IF (IS_GREATER_FUNC(1,2)) THEN
          DBMS_OUTPUT.PUT_LINE(&#8216;TRUE&#8217;);
     ELSE DBMS_OUTPUT.PUT_LINE(&#8216;FALSE&#8217;);
     END IF;
ELSE DBMS_OUTPUT.PUT_LINE(&#8216;FALSE&#8217;);
END IF;</p>

<p>That way, your intention (to only check the second case if the first case is true) is clear, and dependable.  Sure, it&#8217;s more lines of code, but easier to maintain.</p>

<p>Rob</p>
]]></content:encoded>
	</item>
</channel>
</rss>

