<?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: NVL, NVL2 or COALESCE?</title>
	<atom:link href="http://awads.net/wp/2006/01/27/nvl-nvl2-or-coalesce/feed/" rel="self" type="application/rss+xml" />
	<link>http://awads.net/wp/2006/01/27/nvl-nvl2-or-coalesce/</link>
	<description>News, views, tips and tricks on Oracle and other fun stuff</description>
	<pubDate>Mon, 08 Sep 2008 17:24:43 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5</generator>
		<item>
		<title>By: Eddie Awad</title>
		<link>http://awads.net/wp/2006/01/27/nvl-nvl2-or-coalesce/#comment-50047</link>
		<dc:creator>Eddie Awad</dc:creator>
		<pubDate>Fri, 06 Oct 2006 04:59:15 +0000</pubDate>
		<guid isPermaLink="false">http://awads.net/wp/?p=206#comment-50047</guid>
		<description>&lt;p&gt;No, nvl is not limited to select statements.
For example: insert into t (comm) values (nvl(mycomm, 0))&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>No, nvl is not limited to select statements.<br />
For example: insert into t (comm) values (nvl(mycomm, 0))</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: sumanth</title>
		<link>http://awads.net/wp/2006/01/27/nvl-nvl2-or-coalesce/#comment-50035</link>
		<dc:creator>sumanth</dc:creator>
		<pubDate>Fri, 29 Sep 2006 06:47:41 +0000</pubDate>
		<guid isPermaLink="false">http://awads.net/wp/?p=206#comment-50035</guid>
		<description>&lt;p&gt;how to use nvl function and insert statement together... or... usage of nvl is limited to select statements.. please help&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>how to use nvl function and insert statement together&#8230; or&#8230; usage of nvl is limited to select statements.. please help</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Eddie Awad</title>
		<link>http://awads.net/wp/2006/01/27/nvl-nvl2-or-coalesce/#comment-1274</link>
		<dc:creator>Eddie Awad</dc:creator>
		<pubDate>Fri, 27 Jan 2006 23:46:10 +0000</pubDate>
		<guid isPermaLink="false">http://awads.net/wp/?p=206#comment-1274</guid>
		<description>&lt;p&gt;In certain situations in &lt;b&gt;8i&lt;/b&gt;, COALESCE did not behave the same as NVL, in fact it errored out. An example:&lt;/p&gt;

&lt;pre&gt;
user@8i&#62; create table t (id int, f blob)
  2  /

Table created.

user@8i&#62; insert into t (id) values (1)
  2  /

1 row created.

user@8i&#62; select
  2      id
  3      ,dbms_lob.getlength(f)
  4      ,nvl(dbms_lob.getlength(f),0)
  5  from t
  6  /

        ID DBMS_LOB.GETLENGTH(F) NVL(DBMS_LOB.GETLENGTH(F),0)
---------- --------------------- ----------------------------
         1                                                  0

user@8i&#62; select
  2      id
  3      ,dbms_lob.getlength(f)
  4      ,coalesce(dbms_lob.getlength(f),0)
  5  from t
  6  /
    ,coalesce(dbms_lob.getlength(f),0)
     *
ERROR at line 4:
ORA-00904: invalid column name
&lt;/pre&gt;

&lt;p&gt;The above worked in 9i (and XE)&lt;/p&gt;

&lt;pre&gt;
user@9i&#62; create table t (id int, f blob)
  2  /

Table created.

user@9i&#62; insert into t (id) values (1)
  2  /

1 row created.

user@9i&#62; select
  2      id
  3      ,dbms_lob.getlength(f)
  4      ,nvl(dbms_lob.getlength(f),0)
  5  from t
  6  /

        ID DBMS_LOB.GETLENGTH(F) NVL(DBMS_LOB.GETLENGTH(F),0)
---------- --------------------- ----------------------------
         1                                                  0

user@9i&#62; select
  2      id
  3      ,dbms_lob.getlength(f)
  4      ,coalesce(dbms_lob.getlength(f),0)
  5  from t
  6  /

        ID DBMS_LOB.GETLENGTH(F) COALESCE(DBMS_LOB.GETLENGTH(F),0)
---------- --------------------- ---------------------------------
         1                                                       0

&lt;/pre&gt;
</description>
		<content:encoded><![CDATA[<p>In certain situations in <b>8i</b>, COALESCE did not behave the same as NVL, in fact it errored out. An example:</p>
<pre>
user@8i&gt; create table t (id int, f blob)
  2  /

Table created.

user@8i&gt; insert into t (id) values (1)
  2  /

1 row created.

user@8i&gt; select
  2      id
  3      ,dbms_lob.getlength(f)
  4      ,nvl(dbms_lob.getlength(f),0)
  5  from t
  6  /

        ID DBMS_LOB.GETLENGTH(F) NVL(DBMS_LOB.GETLENGTH(F),0)
---------- --------------------- ----------------------------
         1                                                  0

user@8i&gt; select
  2      id
  3      ,dbms_lob.getlength(f)
  4      ,coalesce(dbms_lob.getlength(f),0)
  5  from t
  6  /
    ,coalesce(dbms_lob.getlength(f),0)
     *
ERROR at line 4:
ORA-00904: invalid column name
</pre>
<p>The above worked in 9i (and XE)</p>
<pre>
user@9i&gt; create table t (id int, f blob)
  2  /

Table created.

user@9i&gt; insert into t (id) values (1)
  2  /

1 row created.

user@9i&gt; select
  2      id
  3      ,dbms_lob.getlength(f)
  4      ,nvl(dbms_lob.getlength(f),0)
  5  from t
  6  /

        ID DBMS_LOB.GETLENGTH(F) NVL(DBMS_LOB.GETLENGTH(F),0)
---------- --------------------- ----------------------------
         1                                                  0

user@9i&gt; select
  2      id
  3      ,dbms_lob.getlength(f)
  4      ,coalesce(dbms_lob.getlength(f),0)
  5  from t
  6  /

        ID DBMS_LOB.GETLENGTH(F) COALESCE(DBMS_LOB.GETLENGTH(F),0)
---------- --------------------- ---------------------------------
         1                                                       0
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: gsalem</title>
		<link>http://awads.net/wp/2006/01/27/nvl-nvl2-or-coalesce/#comment-1272</link>
		<dc:creator>gsalem</dc:creator>
		<pubDate>Fri, 27 Jan 2006 22:53:03 +0000</pubDate>
		<guid isPermaLink="false">http://awads.net/wp/?p=206#comment-1272</guid>
		<description>&lt;p&gt;Robert,
I think that the difference in perf mentionned on donald's site (oracledba) is mostly due to the operations used in the tests other than the first one (e.g. nvl(c,to_date('0001','yyyy')) != nvl(d,to_date('0001','yyyy')) where the to_date costs a lot). If you workaround these, then the timing differences are much less important.
rgds&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Robert,<br />
I think that the difference in perf mentionned on donald&#8217;s site (oracledba) is mostly due to the operations used in the tests other than the first one (e.g. nvl(c,to_date(&#8217;0001&#8242;,&#8217;yyyy&#8217;)) != nvl(d,to_date(&#8217;0001&#8242;,&#8217;yyyy&#8217;)) where the to_date costs a lot). If you workaround these, then the timing differences are much less important.<br />
rgds</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Robert Vollman</title>
		<link>http://awads.net/wp/2006/01/27/nvl-nvl2-or-coalesce/#comment-1271</link>
		<dc:creator>Robert Vollman</dc:creator>
		<pubDate>Fri, 27 Jan 2006 22:16:52 +0000</pubDate>
		<guid isPermaLink="false">http://awads.net/wp/?p=206#comment-1271</guid>
		<description>&lt;p&gt;I believe this is the article to which David is referring:&lt;/p&gt;

&lt;p&gt;http://www.oracledba.co.uk/tips/plsql_nvl_costs.htm&lt;/p&gt;

&lt;p&gt;I remember there being another, but I can't find it.&lt;/p&gt;

&lt;p&gt;For the record, I use coalesce in Sybase, but in Oracle that's the one I don't use.  Don't know why.  Probably DECODE is the one I use the most.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>I believe this is the article to which David is referring:</p>
<p><a href="http://www.oracledba.co.uk/tips/plsql_nvl_costs.htm" rel="nofollow">http://www.oracledba.co.uk/tips/plsql_nvl_costs.htm</a></p>
<p>I remember there being another, but I can&#8217;t find it.</p>
<p>For the record, I use coalesce in Sybase, but in Oracle that&#8217;s the one I don&#8217;t use.  Don&#8217;t know why.  Probably DECODE is the one I use the most.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: David Aldridge</title>
		<link>http://awads.net/wp/2006/01/27/nvl-nvl2-or-coalesce/#comment-1270</link>
		<dc:creator>David Aldridge</dc:creator>
		<pubDate>Fri, 27 Jan 2006 17:12:20 +0000</pubDate>
		<guid isPermaLink="false">http://awads.net/wp/?p=206#comment-1270</guid>
		<description>&lt;p&gt;I remember reading recently (on Ask Tom I believe) that Nvl() has the disadvantage that expr2 is always evaluated even when expr1 is not null, which can be expensive if expr2 is non-trivial -- a PL/SQL function call for example.&lt;/p&gt;

&lt;p&gt;That makes Coalesce the winner for me.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>I remember reading recently (on Ask Tom I believe) that Nvl() has the disadvantage that expr2 is always evaluated even when expr1 is not null, which can be expensive if expr2 is non-trivial &#8212; a PL/SQL function call for example.</p>
<p>That makes Coalesce the winner for me.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Karl</title>
		<link>http://awads.net/wp/2006/01/27/nvl-nvl2-or-coalesce/#comment-1269</link>
		<dc:creator>Karl</dc:creator>
		<pubDate>Fri, 27 Jan 2006 15:51:07 +0000</pubDate>
		<guid isPermaLink="false">http://awads.net/wp/?p=206#comment-1269</guid>
		<description>&lt;p&gt;Hey guys!
be honest - i don not beleave that 60% used coalesce?
i always used nvl- the classic NULL -killer :-)
Karl&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Hey guys!<br />
be honest - i don not beleave that 60% used coalesce?<br />
i always used nvl- the classic NULL -killer <img src='http://awads.net/wp/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> Karl</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Laurent Schneider</title>
		<link>http://awads.net/wp/2006/01/27/nvl-nvl2-or-coalesce/#comment-1268</link>
		<dc:creator>Laurent Schneider</dc:creator>
		<pubDate>Fri, 27 Jan 2006 15:20:07 +0000</pubDate>
		<guid isPermaLink="false">http://awads.net/wp/?p=206#comment-1268</guid>
		<description>
  &lt;p&gt;(maybe more?)&lt;/p&gt;


&lt;p&gt;select decode(x,0,null,x) from t;&lt;/p&gt;

&lt;p&gt;is&lt;/p&gt;

&lt;p&gt;select nullif(x,0) from t;&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>(maybe more?)</p>
<p>select decode(x,0,null,x) from t;</p>
<p>is</p>
<p>select nullif(x,0) from t;</p>
]]></content:encoded>
	</item>
</channel>
</rss>
