Search code examples
plsqloracle11g

Converting Boolean to Varchar2


I have a sample code where i'm trying to print Boolean value. It resulted error.

wrong number or types of arguments in call to 'PUT_LINE'

wrong number or types of arguments in call to 'TO_CHAR'

DECLARE
    status BOOLEAN:= false;
    BEGIN
      DBMS_OUTPUT.PUT_LINE(status);
      DBMS_OUTPUT.PUT_LINE(to_char(status));
    END;

By the error message it's clear that Boolean can't be converted to character in both ways (implicit, explicit).

Why its not possible?

Is their any specific reasons? or Oracle just forgot about this type of conversion(Its highly unlikely).

So is their any other way to convert? Or do i have to go for IF or CASE statement to guess what status has.


Solution

  • It seems that there is a new variant TO_CHAR(boolean) in Oracle 23c. https://docs.oracle.com/en/database/oracle/oracle-database/23/sqlrf/to_char-boolean.html