Home » SQL & PL/SQL » SQL & PL/SQL » dbms_output.put_line(boolean) (Oracle 10g, Windows XP)
icon8.gif  dbms_output.put_line(boolean) [message #359955] Tue, 18 November 2008 23:31 Go to next message
raja.or.king
Messages: 24
Registered: November 2008
Location: GJ 5
Junior Member
Helo frends.
I m new to this forum. n asking first query with great hope.

when I print boolean type value using
dbms_output.put_line()
method, I m getting error.

Is it possible to print boolean type value.

Please help.
Re: dbms_output.put_line(boolean) [message #359959 is a reply to message #359955] Tue, 18 November 2008 23:56 Go to previous messageGo to next message
Akash83
Messages: 9
Registered: November 2008
Location: India
Junior Member
Actually DBMS_OUTPUT.PUT_LINE is not overloaded to handle BOOLEAN data type. You can use CASE expressions to convert the Boolean value to a character string which DBMS output can handle.
Re: dbms_output.put_line(boolean) [message #359960 is a reply to message #359955] Wed, 19 November 2008 00:05 Go to previous messageGo to next message
Akash83
Messages: 9
Registered: November 2008
Location: India
Junior Member
Here is a sample code and change this as per your requirement.

DECLARE

BOOLEAN_TRUE BOOLEAN := TRUE;
BOOLEAN_FALSE BOOLEAN := FALSE;
BOOLEAN_NULL BOOLEAN;

FUNCTION BOOLEAN_TO_VARCHAR(FLAG IN BOOLEAN)
RETURN VARCHAR2 IS
BEGIN
RETURN
CASE FLAG
WHEN TRUE THEN 'TRUE'
WHEN FALSE THEN 'FALSE'
ELSE 'NULL'
END;
END;
DBMS_OUTPUT.PUT_LINE(BOOLEAN_TO_VARCHAR(BOOLEAN_TRUE));
DBMS_OUTPUT.PUT_LINE(BOOLEAN_TO_VARCHAR(BOOLEAN_FALSE));
END;
Re: dbms_output.put_line(boolean) [message #359970 is a reply to message #359960] Wed, 19 November 2008 00:48 Go to previous messageGo to next message
Michel Cadot
Messages: 64132
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
@Akash83

Please read OraFAQ Forum Guide, especially "How to format your post?" section.
Make sure that lines of code do not exceed 80 characters when you format.
Indent the code (See SQL Formatter) and use code tags.
Use the "Preview Message" button to verify.

In addition, Don't put solution only hint or clue as requested in OraFAQ Forum Guide, "Responding to Posts" section:
Quote:
When responding to questions, if it is obviously a student with a homework assignment or someone else just learning, especially in the homework and newbies forums, it is usual to provide hints or clues, perhaps links to relevant portions of the documentation, or a similar example, to point them in the right direction so that they will research and experiment on their own and learn, and not provide complete solutions to problems. In cases where someone has a real-life complex work problem, or at least it may seem complex to them, it may be best to provide a complete demo and explanation.


Regards
Michel
Re: dbms_output.put_line(boolean) [message #359989 is a reply to message #359960] Wed, 19 November 2008 02:42 Go to previous messageGo to next message
Frank
Messages: 7880
Registered: March 2000
Senior Member
My teacher in logics always said "Who so ever compares a boolean to TRUE or FALSE has not understood the way booleans work"
  1  declare
  2    l_bool boolean;
  3    function bool_to_text
  4    (p_bool in boolean) return varchar2
  5    is
  6    begin
  7      return case when p_bool then 'TRUE'
  8                  when not p_bool then 'FALSE'
  9                  else 'NULL'
 10             end;
 11    end bool_to_text;
 12  begin
 13    dbms_output.put_line(bool_to_text(l_bool));
 14    l_bool := true;
 15    dbms_output.put_line(bool_to_text(l_bool));
 16    l_bool := false;
 17    dbms_output.put_line(bool_to_text(l_bool));
 18* end;
 19  /
NULL
TRUE
FALSE

PL/SQL procedure successfully completed.
Re: dbms_output.put_line(boolean) [message #359998 is a reply to message #359959] Wed, 19 November 2008 03:01 Go to previous messageGo to next message
raja.or.king
Messages: 24
Registered: November 2008
Location: GJ 5
Junior Member
Thank u Akask.

but i think, put_line() method can take value of only one type, that is varhcar2, as a parameter, then also it can print date n number type values. why not boolean?
Re: dbms_output.put_line(boolean) [message #360007 is a reply to message #359998] Wed, 19 November 2008 03:35 Go to previous messageGo to next message
Michel Cadot
Messages: 64132
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
It prints number or date ONLY because there is an implicit conversion to VARCHAR2 which does not exist with boolean datatype.

Regards
Michel
icon7.gif  Re: dbms_output.put_line(boolean) [message #360012 is a reply to message #360007] Wed, 19 November 2008 03:49 Go to previous messageGo to next message
raja.or.king
Messages: 24
Registered: November 2008
Location: GJ 5
Junior Member
Yes, I got it.

Thanks all.
Re: dbms_output.put_line(boolean) [message #360056 is a reply to message #359955] Wed, 19 November 2008 07:05 Go to previous messageGo to next message
mail2das.ashok
Messages: 10
Registered: May 2008
Junior Member
Boolean data type is actually used for logical comaprison.

so u can't use it the way as u are saying
Re: dbms_output.put_line(boolean) [message #360068 is a reply to message #360056] Wed, 19 November 2008 07:48 Go to previous message
Michel Cadot
Messages: 64132
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
I don't what "u" says and what "u" can do but "u" can hear you as "u" is not a member of this forum.

Please read OraFAQ Forum Guide.

Regards
Michel
Previous Topic: mutating table error with an extra trigger
Next Topic: ORA-01406: fetched column value was truncated
Goto Forum:
  


Current Time: Wed Dec 07 18:37:22 CST 2016

Total time taken to generate the page: 0.23406 seconds