boolean variable 's default value? [message #10109] |
Mon, 05 January 2004 23:22 |
sancha
Messages: 31 Registered: October 2003
|
Member |
|
|
Hi All,
the following code is meant to find the default value of a boolean variable:
declare
a boolean;
begin
dbms_output.put_line(a || ' hi') ;
end;
i dont get any value when i run this code.
pls tell me how the default value can be found?
|
|
|
Re: boolean variable 's default value? [message #10110 is a reply to message #10109] |
Mon, 05 January 2004 23:43 |
Prashanth
Messages: 41 Registered: September 1999
|
Member |
|
|
default is FALSE
try this
declare
a boolean;
begin
if(a) then
dbms_output.put_line('TRUE') ;
else
dbms_output.put_line('FALSE') ;
end if;
end;
Result will be FALSE.
and as such, u cannot print Boolean Variables
|
|
|
Re: boolean variable's default value? [message #10145 is a reply to message #10110] |
Tue, 06 January 2004 05:56 |
Art Metzer
Messages: 2480 Registered: December 2002
|
Senior Member |
|
|
The previous post is wrong: the default value for a BOOLEAN is not FALSE, but NULL.Witness:SQL> DECLARE
2 a BOOLEAN;
3 BEGIN
4 IF (a) THEN
5 DBMS_OUTPUT.PUT_LINE('TRUE');
6 ELSIF (NOT a) THEN
7 DBMS_OUTPUT.PUT_LINE('FALSE');
8 ELSE
9 DBMS_OUTPUT.PUT_LINE('Something else');
10 END IF;
11 END;
12 /
Something else
PL/SQL procedure successfully completed.
SQL> Obviously, if the default value for a BOOLEAN were FALSE, "FALSE" would have been printed above instead of "Something else".
Just as an unspecified NUMBER or VARCHAR2 variable has a NULL value, so does an unspecified BOOLEAN variable.
The previous post's misconception is so common that Oracle has devoted a small section of its PL/SQL User's Guide and Reference to it.
Hope this helps,
A.
|
|
|
|