Oracle PL/SQL - PL SQL Data Type BOOLEAN type

Introduction

PL/SQL has a BOOLEAN data type to store logical condition values: TRUE, FALSE, or NULL.

You declare it as shown here:

declare
    variable1_b BOOLEAN;
    ...

Because there is no corresponding SQL data type, you cannot use Boolean variables outside of pure PL/SQL.

Boolean variables can be assigned either directly by using values TRUE, FALSE, or NULL or as the results of logical expressions.

You can use Boolean variables for all conditional structures: IF, CASE, EXIT WHEN, and so on.

There was no need to include v_b = TRUE because the result of the comparison will also be a Boolean value.

Demo

SQL>
SQL> declare--   w w  w  .j  a v a2  s. c  o  m
  2       v_b BOOLEAN:=false;
  3  begin
  4       v_b:=extract(year from sysdate)>2000;
  5       if v_b
  6       then
  7           DBMS_OUTPUT.put_line('21st Century!');
  8       end if;
  9  end;
 10  /
21st Century!

PL/SQL procedure successfully completed.
SQL>

Related Topic