Oracle PL/SQL - BOOLEAN Data Type

Introduction

The PL/SQL data type BOOLEAN stores logical values, which are the Boolean values TRUE and FALSE and the value NULL.

NULL represents an unknown value.

The syntax for declaring an BOOLEAN variable is:

variable_name BOOLEAN 

The only value that you can assign to a BOOLEAN variable is a BOOLEAN expression.

In the following, the procedure accepts a BOOLEAN parameter and uses a CASE statement to print Unknown if the value of the parameter is NULL, Yes if it is TRUE, and No if it is FALSE.

Demo

SQL>
SQL> CREATE PROCEDURE print_boolean (b BOOLEAN) AUTHID DEFINER
  2  AS-- w ww  .ja  va 2  s . c o m
  3  BEGIN
  4    DBMS_OUTPUT.put_line (
  5      CASE
  6        WHEN b IS NULL THEN 'Unknown'
  7        WHEN b THEN 'Yes'
  8        WHEN NOT b THEN 'No'
  9      END
 10    );
 11  END;
 12  /

SQL> BEGIN
  2    print_boolean(TRUE);
  3    print_boolean(FALSE);
  4    print_boolean(NULL);
  5  END;
  6  /

SQL>

Related Topics