<?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>Wed, 30 Nov 2011 17:41:41 +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[<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>

