viernes, 21 de diciembre de 2007

Valor NULL en sentencia IF

Necesitamos evaluar si contenido de una variable denominada nombre contiene la cadena de caracteres 'JAVIER'.
En el primer ejemplo asignamos a la variable nombre el valor NULL. La condición nombre != 'JAVIER' se evalúa como NULL != 'JAVIER' y resulta FALSA! El valor NULL es distinto de la cadena de caracteres 'JAVIER', sin embargo la ejecución se bifurca por la rama del ELSE. Se muestra el mensaje 'CONDICION FALSA, SON IGUALES. EJECUTA ELSE.'. Dónde está el error?
SQL> RUN
1 DECLARE
2 nombre VARCHAR2(40) := NULL;
3 BEGIN
4 IF nombre != 'JAVIER' THEN
5 DBMS_OUTPUT.PUT_LINE('CONDICION VERDADERA, SON DISTINTOS. EJECUTA THEN.');
6 ELSE
7 DBMS_OUTPUT.PUT_LINE('CONDICION FALSA, SON IGUALES. EJECUTA ELSE.');
8 END IF;
9* END;

CONDICION FALSA, SON IGUALES. EJECUTA ELSE.

Procedimiento PL/SQL terminado con éxito.

En el segundo ejemplo asignamos a la variable nombre la cadena de caracteres 'NULL'. La condición nombre != 'JAVIER' se evalúa como una comparación entre dos cadenas de caracteres 'NULL' != 'JAVIER' y resulta VERDADERA! Se muestra el mensaje 'CONDICION VERDADERA, SON DISTINTOS. EJECUTA THEN.'.
SQL> RUN
1 DECLARE
2 nombre VARCHAR2(40) := 'NULL';
3 BEGIN
4 IF nombre != 'JAVIER' THEN
5 DBMS_OUTPUT.PUT_LINE('CONDICION VERDADERA, SON DISTINTOS. EJECUTA THEN.');
6 ELSE
7 DBMS_OUTPUT.PUT_LINE('CONDICION FALSA, SON IGUALES. EJECUTA ELSE.');
8 END IF;
9* END;

CONDICION VERDADERA, SON DISTINTOS. EJECUTA THEN.

Procedimiento PL/SQL terminado con éxito.

La clave es entender que la evaluación de condiciones que contienen al menos un elemento con valor NULL, SIEMPRE resultan FALSAS. La única excepción es la cláusula IS NULL.

NULL != 'JAVIER' es FALSO
NULL = 'JAVIER' es FALSO
NULL = NULL es FALSO

NULL IS NULL es VERDADERO
NULL IS NOT NULL es FALSO

En el tercer ejemplo tomamos precauciones para no repetir el comportamiento inesperado del primer ejemplo. Modificamos la línea 4 de evaluación de la condición agregando la función NVL que reemplazará los valores nulos de la variable nombre por la cadena de caracteres 'VALOR NULO'. Ahora si, la condición 'VALOR NULO' != 'JAVIER' es VERDADERA.
SQL> RUN
1 DECLARE
2 nombre VARCHAR2(40) := NULL;
3 BEGIN
4 IF NVL(nombre,'VALOR NULO') != 'JAVIER' THEN
5 DBMS_OUTPUT.PUT_LINE('CONDICION VERDADERA, SON DISTINTOS. EJECUTA THEN.');
6 ELSE
7 DBMS_OUTPUT.PUT_LINE('CONDICION FALSA, SON IGUALES. EJECUTA ELSE.');
8 END IF;
9* END;

CONDICION VERDADERA, SON DISTINTOS. EJECUTA THEN.

Procedimiento PL/SQL terminado con éxito.

19 comentarios:

CresceNet dijo...

Gostei muito desse post e seu blog é muito interessante, vou passar por aqui sempre =) Depois dá uma passada lá no meu site, que é sobre o CresceNet, espero que goste. O endereço dele é http://www.provedorcrescenet.com . Um abraço.

Notebooks dijo...

Hello. This post is likeable, and your blog is very interesting, congratulations :-). I will add in my blogroll =). If possible gives a last there on my blog, it is about the Notebook, I hope you enjoy. The address is http://notebooks-brasil.blogspot.com. A hug.

Anónimo dijo...

miley cyrus nude [url=http://crystal-liu.com/forums/index.php?showuser=1113]miley cyrus nude[/url] miley cyrus sex tape [url=http://forum.ondertitel.com/index.php?showuser=74503]miley cyrus sex tape[/url] miley cyrus nude [url=http://stabilo.forumsunlimited.com/index.php?showuser=799]miley cyrus nude[/url] miley cyrus nude [url=http://ragga-jungle.com/user/15036-vebsterd]miley cyrus nude[/url] kim kardashian nude [url=http://forums.quark.com/members/vebsterd.aspx]kim kardashian nude[/url]

Anónimo dijo...

miley cyrus nude [url=http://www.ipetitions.com/petition/mileycyrus]miley cyrus nude[/url] paris hilton nude [url=http://www.ipetitions.com/petition/parishilt]paris hilton nude[/url] kim kardashian nude [url=http://www.ipetitions.com/petition/kimkardashian45]kim kardashian nude[/url] kim kardashian nude [url=http://www.ipetitions.com/petition/celebst]kim kardashian nude[/url]

Anónimo dijo...

play free majong games

http://majong.socialgo.com

Anónimo dijo...

http://13dfgsdfg57.com/

Anónimo dijo...

Hi, guantanamera121212

Anónimo dijo...

ebook zinio crack http://audiobookscollection.co.uk/it/Sistemi-di-Analisi-e-Progettazione/c2450/ psychometric test free ebook [url=http://audiobookscollection.co.uk/fr/Conception-graphique/c1212/?page=5]ebook liptak[/url] peter david ebook torrent

Anónimo dijo...

ebook 0-495-09635-0 http://audiobookscollection.co.uk/es/Absolute-BSD-the-ultimate-guide-to-BSD/p104148/ castillo statistics ebook extreme value [url=http://audiobookscollection.co.uk/Machine-Learning-ECML-97-9th-European-Conference-on-Machine-Learning-Prague-Czech-Republic-April-23-25-1997-Proceedings/p192345/]ebooks new releases ebooks ebook business[/url] post rehab exercise ebook

Anónimo dijo...

free download cluster ebook with pdf http://audiobookscollection.co.uk/fr/Mathematics/p104542/ learning jquery ebook downloads [url=http://audiobookscollection.co.uk/de/Gaelle-Pierre/m41146/]free vampire erotica ebook websites[/url] the math curse ebook

Anónimo dijo...

best resource using virus software http://buyoem.co.uk/product-36347/Bitvise-WinSSHD-5-2 computer menu driven software [url=http://buyoem.co.uk/it/product-37355/Ultra-WMV-Converter-5-2]gps topo software review[/url] outsource software development offshore
[url=http://buyoem.co.uk/category-10/Internet?page=3]Internet - Software Store[/url] acquisition software for openlab
[url=http://buyoem.co.uk/it/product-37380/Chily-Registry-Cleaner-7-1][img]http://buyoem.co.uk/image/7.gif[/img][/url]

Anónimo dijo...

blackjack counting software http://buysoftwareonline.co.uk/category-100-105/PC-Diagnostics?page=2 will autodialer software work with magicjack [url=http://buysoftwareonline.co.uk/de/product-37299/UltimateZip-4-0-Portable]opensource software for apparel patterns[/url] panda software poland
[url=http://buysoftwareonline.co.uk/category-100-110/Internet?page=2]Internet - Software Store[/url] dv editing software video
[url=http://buysoftwareonline.co.uk/fr/product-35379/3herosoft-Video-to-Audio-Converter-3-5-MacOSX][img]http://buyoem.co.uk/image/6.gif[/img][/url]

Anónimo dijo...

[url=http://certifiedpharmacy.co.uk/products/acticin.htm][img]http://onlinemedistore.com/6.jpg[/img][/url]
australian college of pharmacy practice http://certifiedpharmacy.co.uk/products/chloroquine.htm purchase evista pharmacy online [url=http://certifiedpharmacy.co.uk/products/protonix.htm]pharmacy aruba[/url]
free practice test for pharmacy technician http://certifiedpharmacy.co.uk/products/fludac.htm pharmacy open 24 hours in tennessee [url=http://certifiedpharmacy.co.uk/products/hytrin.htm]hytrin[/url]
overseas foreign drugs pharmacy http://certifiedpharmacy.co.uk/products/calan.htm university of maryland college of pharmacy [url=http://certifiedpharmacy.co.uk/catalogue/b.htm]cyber pharmacy phentermine[/url]
australian jounral of hospitla pharmacy 1992 volume 22 http://certifiedpharmacy.co.uk/products/viramune.htm pharmacy university grade requirements in the uk [url=http://certifiedpharmacy.co.uk/products/caverta.htm]caverta[/url]

Anónimo dijo...

[url=http://certifiedpharmacy.co.uk/products/prevacid.htm][img]http://onlinemedistore.com/5.jpg[/img][/url]
canadian pharmacy ultram http://certifiedpharmacy.co.uk/products/hyzaar.htm new world pharmacy south africa [url=http://certifiedpharmacy.co.uk/products/serevent.htm]link online pharmacy[/url]
pre pharmacy schools sc http://certifiedpharmacy.co.uk/products/aldactone.htm applied pharmacy services list [url=http://certifiedpharmacy.co.uk/products/mentat.htm]mentat[/url]
anthem rx pharmacy http://certifiedpharmacy.co.uk/catalogue/g.htm pelletization in pharmacy [url=http://certifiedpharmacy.co.uk/products/motrin.htm]shippees pharmacy wanaque[/url]
nys board of pharmacy http://certifiedpharmacy.co.uk/products/prevacid.htm us prescription pharmacy [url=http://certifiedpharmacy.co.uk/products/diclofenac-gel.htm]diclofenac gel[/url]

Anónimo dijo...

Hi, i fеel that i saw you vіsited my
blog thuѕ i сame to go bасk the desire?
.I am attеmpting to find things to impгoνe mу ѕite!

I assume its goοd enough to use а
feω of your iԁеas!!

Also vіsit mу site: payday loans

Anónimo dijo...

[url=http://certifiedpharmacy.co.uk/products/mentat.htm][img]http://onlinemedistore.com/1.jpg[/img][/url]
joshua pharmacy joshua tx http://certifiedpharmacy.co.uk/categories/antiviral.htm find the best college for a pharmacy degree [url=http://certifiedpharmacy.co.uk/products/atrovent.htm]accreditation council for pharmacy education[/url]
walgreens pharmacy fax number http://certifiedpharmacy.co.uk/products/tofranil.htm greens road pharmacy [url=http://certifiedpharmacy.co.uk/products/adalat.htm]adalat[/url]
finacial aid for pharmacy students in us http://certifiedpharmacy.co.uk/products/cordarone.htm gatti pharmacy [url=http://certifiedpharmacy.co.uk/catalogue/g.htm]new jersey board of pharmacy[/url]
pharmacy meds http://certifiedpharmacy.co.uk/products/leukeran.htm online pain pharmacy relief [url=http://certifiedpharmacy.co.uk/products/kamasutra-dotted-condoms.htm]kamasutra dotted condoms[/url]

Anónimo dijo...

[url=http://certifiedpharmacy.co.uk/categories/anti-acidity.htm][img]http://onlinemedistore.com/9.jpg[/img][/url]
university of tennessee college of pharmacy http://certifiedpharmacy.co.uk/products/symmetrel.htm pharmacy endocrine disruptors [url=http://certifiedpharmacy.co.uk/products/himplasia.htm]grant proposal pharmacy[/url]
texas pharmacy board complaints http://certifiedpharmacy.co.uk/products/zestril.htm cvs pharmacy college kansas [url=http://certifiedpharmacy.co.uk/products/flomax.htm]flomax[/url]
online us pharmacy http://certifiedpharmacy.co.uk/products/procalisx.htm pharmacy lamp [url=http://certifiedpharmacy.co.uk/products/generic-imitrex.htm]dave coverly pharmacy[/url]
foreign pharmacy degrees recognized by fpgee http://certifiedpharmacy.co.uk/products/entocort.htm pusan pharmacy [url=http://certifiedpharmacy.co.uk/products/amaryl.htm]amaryl[/url]

Anónimo dijo...

[url=http://englandpharmacy.co.uk/products/relafen.htm][img]http://onlinemedistore.com/11.jpg[/img][/url]
ellingsons pharmacy oregon http://englandpharmacy.co.uk/catalogue/v.htm overseas pharmacy valium free forum [url=http://englandpharmacy.co.uk/products/pepcid.htm]canadian pharmacy lunesta[/url]
pharmacy meds http://englandpharmacy.co.uk/products/apcalis-oral-jelly.htm state pharmacy assistance [url=http://englandpharmacy.co.uk/products/erectalis.htm]erectalis[/url]
archers and pharmacy and sweetwater http://englandpharmacy.co.uk/categories/blood-pressure.htm pharmacy drug listings [url=http://englandpharmacy.co.uk/products/phenergan.htm]sc pharmacy association[/url]
cvs pharmacy danbury ct http://englandpharmacy.co.uk/products/lamisil.htm denver 24 hour pharmacy albert [url=http://englandpharmacy.co.uk/products/eurax.htm]eurax[/url]

Anónimo dijo...

simple book keeping software http://downloadoemsoftware.co.uk/it/product-15005/gSync-1-0-Mac palm scrabble software [url=http://downloadoemsoftware.co.uk/product-36578/Microsoft-Windows-7-Ultimate-x64-Arabic]shepards software games children[/url] gis software companies
[url=http://downloadoemsoftware.co.uk/category-100-110/Internet?page=2]Internet - Software Store[/url] best software ipod
[url=http://downloadoemsoftware.co.uk/product-36219/Axonic-AppointmentStyler-1-2][img]http://buyoem.co.uk/image/5.gif[/img][/url]