Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Why does the IS NULL stament work diferent for Varchar2 and char

437319Jan 28 2005 — edited Jan 31 2005
Why does the IS NULL stament work diferent for Varchar2,varchar and char?
The next procedure can explain what I'm talking about:

CREATE OR REPLACE PROCEDURE try_isnull IS
n VARCHAR(10):='';
n2 VARCHAR2(10):='';
n3 CHAR(10):='';

BEGIN
--Without space
IF n IS NULL THEN
DBMS_OUTPUT.PUT_LINE('N is NULL');
END IF;

IF n2 IS NULL THEN
DBMS_OUTPUT.PUT_LINE('N2 is NULL');
END IF;

IF n3 IS NULL THEN
DBMS_OUTPUT.PUT_LINE('N3 is NULL');
END IF;

n:=' ';
n2:=' ';
n3:=' ';

--With space
IF n IS NULL THEN
DBMS_OUTPUT.PUT_LINE('N is NULL');
END IF;

IF n2 IS NULL THEN
DBMS_OUTPUT.PUT_LINE('N2 is NULL');
END IF;

IF n3 IS NULL THEN
DBMS_OUTPUT.PUT_LINE('N3 is NULL');
END IF;

n:= NULL;
n2:=NULL;
n3:=NULL;

--With NULL
IF n IS NULL THEN
DBMS_OUTPUT.PUT_LINE('N is NULL');
END IF;

IF n2 IS NULL THEN
DBMS_OUTPUT.PUT_LINE('N2 is NULL');
END IF;

IF n3 IS NULL THEN
DBMS_OUTPUT.PUT_LINE('N3 is NULL');
END IF;

END;

Why Do they work different ? For me NULL is nothing, So, the rigth behavor should be the char behave.
Does somebody have any answer?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 28 2005
Added on Jan 28 2005
5 comments
138 views