<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>glufke.net &#187; NULL</title>
	<atom:link href="http://glufke.net/tag/null/feed/" rel="self" type="application/rss+xml" />
	<link>http://glufke.net</link>
	<description></description>
	<lastBuildDate>Mon, 16 Apr 2012 19:33:42 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Comparação de Campos com NULL</title>
		<link>http://glufke.net/2007/09/06/comparacao-de-campos-com-null/</link>
		<comments>http://glufke.net/2007/09/06/comparacao-de-campos-com-null/#comments</comments>
		<pubDate>Thu, 06 Sep 2007 13:34:52 +0000</pubDate>
		<dc:creator>glufke</dc:creator>
				<category><![CDATA[PL/SQL]]></category>
		<category><![CDATA[Curiosidade]]></category>
		<category><![CDATA[NULL]]></category>

		<guid isPermaLink="false">http://glufke.net/2007/09/06/comparacao-de-campos-com-null/</guid>
		<description><![CDATA[
			
			
			
			
			
			
			
						
			Sabemos que quando um variável ou um campo no Oracle está NULL, ele não pode ser simplesmente comparado a um outro valor, pois o resultado da compração também será false!

declare
  a number:=null;
  b number:=null;
begin
  if a=b
  then dbms_output.put_line('SIM');
  else  dbms_output.put_line('nao');
  end if;
end;

SQL> /
nao



POUCO EFICIENTE
Para &#8220;sanar&#8221; este problema, é [...]]]></description>
			<content:encoded><![CDATA[<div class="bottomcontainerBox" style="">
			<div style="float:left; width:50px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fglufke.net%2F2007%2F09%2F06%2Fcomparacao-de-campos-com-null%2F&amp;layout=button_count&amp;show_faces=false&amp;width=50&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:50px; height:21px;"></iframe></div>
			<div style="float:left; width:60px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<g:plusone size="medium" href="http://glufke.net/2007/09/06/comparacao-de-campos-com-null/"></g:plusone>
			</div>
			<div style="float:left; width:70px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<a href="http://twitter.com/share" class="twitter-share-button" data-url="http://glufke.net/2007/09/06/comparacao-de-campos-com-null/"  data-text="Comparação de Campos com NULL" data-count="horizontal" data-via="glufke"></a>
			</div><div style="float:left; width:110px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script type="in/share" data-url="http://glufke.net/2007/09/06/comparacao-de-campos-com-null/" data-counter="right"></script></div>			
			</div><div style="clear:both"></div><div style="padding-bottom:4px;"></div><p>Sabemos que quando um variável ou um campo no Oracle está NULL, ele não pode ser simplesmente comparado a um outro valor, pois o resultado da compração também será false!<span id="more-10"></span></p>
<pre class="brush: sql;">
declare
  a number:=null;
  b number:=null;
begin
  if a=b
  then dbms_output.put_line('SIM');
  else  dbms_output.put_line('nao');
  end if;
end;

SQL> /
nao
</pre>
<div id="ads_336x280"><script type="text/javascript"><!--
google_ad_client = "pub-8964513116661040";
google_alternate_color = "ffffFF";
google_ad_width = 336;
google_ad_height = 280;
google_ad_format = "336x280_as";
google_ad_type = "text_image";
//2007-09-07: wp_quadrado_gra
google_ad_channel = "0247072216";
google_color_border = "FFFFFF";
google_color_bg = "FFFFff";
google_color_link = "4F82CB";
google_color_text = "000000";
google_color_url = "4F82CB";
//--></script><script type="text/javascript"
  src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>
<p><strong>POUCO EFICIENTE</strong><br />
Para &#8220;sanar&#8221; este problema, é possivel usar NVL, que não é uma boa prática. Veremos porque:</p>
<pre class="brush: sql;">
if nvl(a, 123456789) = nvl(b, 123456789)
then --seu código
</pre>
<p>O exemplo acima até funciona se o valor for diferente de 123456789. Se o valor for igual, ferra a comparação!</p>
<p><strong>MUITO EFICIENTE</strong><br />
A melhor prática possível<br />
É um pouco trabalhosa, mas sempre funcionará:</p>
<pre class="brush: sql;">
if a<>b
or (a is null and b is not null)
or (a is not null and b is null)
then --seu codigo
</pre>
<p>Comente <a href="http://glufke.net/oracle/viewtopic.php?p=343">aqui</a></p>
]]></content:encoded>
			<wfw:commentRss>http://glufke.net/2007/09/06/comparacao-de-campos-com-null/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

