<?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:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: NVL2()</title>
	<atom:link href="http://jonathanlewis.wordpress.com/2012/04/23/nvl2/feed/" rel="self" type="application/rss+xml" />
	<link>http://jonathanlewis.wordpress.com/2012/04/23/nvl2/</link>
	<description>Just another Oracle weblog</description>
	<lastBuildDate>Sat, 18 May 2013 11:04:10 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
	<item>
		<title>By: Jonathan Lewis</title>
		<link>http://jonathanlewis.wordpress.com/2012/04/23/nvl2/#comment-46224</link>
		<dc:creator><![CDATA[Jonathan Lewis]]></dc:creator>
		<pubDate>Mon, 30 Apr 2012 14:32:20 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=8811#comment-46224</guid>
		<description><![CDATA[Thanks for the responses everyone.

This is one reason why I like the blogging environment to the old Web Page approach. It allows other people to add value to the original article and reveal extra benefits (or problems, or version-dependencies) that you wouldn&#039;t necessarily find out for yourself until it&#039;s too late.]]></description>
		<content:encoded><![CDATA[<p>Thanks for the responses everyone.</p>
<p>This is one reason why I like the blogging environment to the old Web Page approach. It allows other people to add value to the original article and reveal extra benefits (or problems, or version-dependencies) that you wouldn&#8217;t necessarily find out for yourself until it&#8217;s too late.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jgarry</title>
		<link>http://jonathanlewis.wordpress.com/2012/04/23/nvl2/#comment-46170</link>
		<dc:creator><![CDATA[jgarry]]></dc:creator>
		<pubDate>Tue, 24 Apr 2012 20:58:46 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=8811#comment-46170</guid>
		<description><![CDATA[Also more useful if they work.  See MOS Bug 5490501 - Wrong Results with COALESCE or NVL2 on aggregations inside subqueries [ID 5490501.8]

The wrap issue is explained in &lt;a href=&quot;https://support.oracle.com/CSP/main/article?cmd=show&amp;type=NOT&amp;doctype=BULLETIN&amp;id=269973.1&quot; rel=&quot;nofollow&quot;&gt;How to Find out the Reason for PLS-00201 in PL/SQL [ID 269973.1]&lt;/a&gt;: &quot;Some recent SQL syntax is not supported by the wrap utility by default.  To enable the support for all SQL syntax, specify the option edebug=wrap_new_sql (with no dash). &quot;]]></description>
		<content:encoded><![CDATA[<p>Also more useful if they work.  See MOS Bug 5490501 &#8211; Wrong Results with COALESCE or NVL2 on aggregations inside subqueries [ID 5490501.8]</p>
<p>The wrap issue is explained in <a href="https://support.oracle.com/CSP/main/article?cmd=show&amp;type=NOT&amp;doctype=BULLETIN&amp;id=269973.1" rel="nofollow">How to Find out the Reason for PLS-00201 in PL/SQL [ID 269973.1]</a>: &#8220;Some recent SQL syntax is not supported by the wrap utility by default.  To enable the support for all SQL syntax, specify the option edebug=wrap_new_sql (with no dash). &#8220;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Raj</title>
		<link>http://jonathanlewis.wordpress.com/2012/04/23/nvl2/#comment-46165</link>
		<dc:creator><![CDATA[Raj]]></dc:creator>
		<pubDate>Tue, 24 Apr 2012 10:25:19 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=8811#comment-46165</guid>
		<description><![CDATA[@Kieran,

I never seem to have any problems with nvl2 apart from the fact that nvl2 is not supported in a pl/sql context for some reason.

&lt;code&gt;
3:1051:45945:11234&gt;select * from v$version;

BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64bit Production
PL/SQL Release 11.1.0.7.0 - Production
CORE    11.1.0.7.0      Production
TNS for Linux: Version 11.1.0.7.0 - Production
NLSRTL Version 11.1.0.7.0 - Production

3:1051:45945:11234&gt;@ c:\work\sql_scripts\t.sql

Function created.

3:1051:45945:11234&gt;select text from user_Source where name = &#039;TEST_FUNC&#039;;

TEXT
----------------------------------------------------------------------------------------------------
function test_func(pi_input Varchar2)
return varchar2
is
   l_Status Varchar2(10);
Begin
   select nvl2(pi_input, &#039;Not Null&#039;, &#039;Null&#039;) into l_status
   from dual;
   return l_Status;
end;

9 rows selected.

3:1051:45945:11234&gt;select test_func(null) from dual;

TEST_FUNC(NULL)
----------------------------------------------------------------------------------------------------
Null

C:\work\sql_scripts&gt;wrap iname=t.sql oname=t.plb

PL/SQL Wrapper: Release 10.2.0.1.0- Production on Tue Apr 24 11:18:34 2012

Copyright (c) 1993, 2004, Oracle.  All rights reserved.

Processing t.sql to t.plb

3:1051:45945:11234&gt;@ c:\work\sql_scripts\t.plb

Function created.

3:1051:45945:11234&gt;select text from user_Source where name = &#039;TEST_FUNC&#039;;

TEXT
----------------------------------------------------------------------------------------------------
function test_func wrapped
snipped

3:1051:45945:11234&gt;select test_func(null) from dual;

TEST_FUNC(NULL)
----------------------------------------------------------------------------------------------------
Null

3:1051:45945:11234&gt;select test_func(&#039;hello&#039;) from dual;

TEST_FUNC(&#039;HELLO&#039;)
----------------------------------------------------------------------------------------------------
Not Null

3:1051:45945:11234&gt;

&lt;/code&gt;

Thanks]]></description>
		<content:encoded><![CDATA[<p>@Kieran,</p>
<p>I never seem to have any problems with nvl2 apart from the fact that nvl2 is not supported in a pl/sql context for some reason.</p>
<p><code><br />
3:1051:45945:11234&gt;select * from v$version;</p>
<p>BANNER<br />
--------------------------------------------------------------------------------<br />
Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64bit Production<br />
PL/SQL Release 11.1.0.7.0 - Production<br />
CORE    11.1.0.7.0      Production<br />
TNS for Linux: Version 11.1.0.7.0 - Production<br />
NLSRTL Version 11.1.0.7.0 - Production</p>
<p>3:1051:45945:11234&gt;@ c:\work\sql_scripts\t.sql</p>
<p>Function created.</p>
<p>3:1051:45945:11234&gt;select text from user_Source where name = 'TEST_FUNC';</p>
<p>TEXT<br />
----------------------------------------------------------------------------------------------------<br />
function test_func(pi_input Varchar2)<br />
return varchar2<br />
is<br />
   l_Status Varchar2(10);<br />
Begin<br />
   select nvl2(pi_input, 'Not Null', 'Null') into l_status<br />
   from dual;<br />
   return l_Status;<br />
end;</p>
<p>9 rows selected.</p>
<p>3:1051:45945:11234&gt;select test_func(null) from dual;</p>
<p>TEST_FUNC(NULL)<br />
----------------------------------------------------------------------------------------------------<br />
Null</p>
<p>C:\work\sql_scripts&gt;wrap iname=t.sql oname=t.plb</p>
<p>PL/SQL Wrapper: Release 10.2.0.1.0- Production on Tue Apr 24 11:18:34 2012</p>
<p>Copyright (c) 1993, 2004, Oracle.  All rights reserved.</p>
<p>Processing t.sql to t.plb</p>
<p>3:1051:45945:11234&gt;@ c:\work\sql_scripts\t.plb</p>
<p>Function created.</p>
<p>3:1051:45945:11234&gt;select text from user_Source where name = 'TEST_FUNC';</p>
<p>TEXT<br />
----------------------------------------------------------------------------------------------------<br />
function test_func wrapped<br />
snipped</p>
<p>3:1051:45945:11234&gt;select test_func(null) from dual;</p>
<p>TEST_FUNC(NULL)<br />
----------------------------------------------------------------------------------------------------<br />
Null</p>
<p>3:1051:45945:11234&gt;select test_func('hello') from dual;</p>
<p>TEST_FUNC('HELLO')<br />
----------------------------------------------------------------------------------------------------<br />
Not Null</p>
<p>3:1051:45945:11234&gt;</p>
<p></code></p>
<p>Thanks</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kieran Walsh</title>
		<link>http://jonathanlewis.wordpress.com/2012/04/23/nvl2/#comment-46160</link>
		<dc:creator><![CDATA[Kieran Walsh]]></dc:creator>
		<pubDate>Mon, 23 Apr 2012 20:57:55 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=8811#comment-46160</guid>
		<description><![CDATA[I fell in love with NVL2 for about a week - and then realised that it wasn&#039;t a supported construct under the WRAP tool, so it was back to decodes. Sigh.]]></description>
		<content:encoded><![CDATA[<p>I fell in love with NVL2 for about a week &#8211; and then realised that it wasn&#8217;t a supported construct under the WRAP tool, so it was back to decodes. Sigh.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sayan Malakshinov</title>
		<link>http://jonathanlewis.wordpress.com/2012/04/23/nvl2/#comment-46158</link>
		<dc:creator><![CDATA[Sayan Malakshinov]]></dc:creator>
		<pubDate>Mon, 23 Apr 2012 19:39:45 +0000</pubDate>
		<guid isPermaLink="false">http://jonathanlewis.wordpress.com/?p=8811#comment-46158</guid>
		<description><![CDATA[The nvl2 function is really more appropriate for such fbi in fact, since it is faster than the &quot;decode (x, null, 1)&quot; and, although a little slower than the &quot;case when x is null then 1 end&quot;, but more readable and shorter.
[sourcecode language=&quot;SQL&quot; collapse=&quot;true&quot;]
with gen as (
            select n
            from (select level from dual connect by level&lt;=1e6)
                ,(select 1 n from dual
                  union all 
                  select null from dual
                 ) t
)
select sum(nvl2(n,null,1))                 --1.046 secs
       --sum(decode(n,null,1))               -- 1.482 secs
       --sum(case when n is null then 1 end) --0.982 seconds
from gen
/
[/sourcecode]
But it also has disadvantages. For example, in contrast to &quot;decode&quot; it evaluates all its arguments.]]></description>
		<content:encoded><![CDATA[<p>The nvl2 function is really more appropriate for such fbi in fact, since it is faster than the &#8220;decode (x, null, 1)&#8221; and, although a little slower than the &#8220;case when x is null then 1 end&#8221;, but more readable and shorter.</p>
<pre class="brush: sql; collapse: true; light: false; title: ; toolbar: true; notranslate">
with gen as (
            select n
            from (select level from dual connect by level&lt;=1e6)
                ,(select 1 n from dual
                  union all 
                  select null from dual
                 ) t
)
select sum(nvl2(n,null,1))                 --1.046 secs
       --sum(decode(n,null,1))               -- 1.482 secs
       --sum(case when n is null then 1 end) --0.982 seconds
from gen
/
</pre>
<p>But it also has disadvantages. For example, in contrast to &#8220;decode&#8221; it evaluates all its arguments.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
