Oracle PL/SQL - Assigning Values to BOOLEAN Variables

Introduction

The only values that you can assign to a BOOLEAN variable are TRUE, FALSE, and NULL.

The following code initializes the BOOLEAN variable done to NULL by default.

Then it assigns it the literal value FALSE, compares it to the literal value TRUE, and assigns it the value of a BOOLEAN expression.

Demo

SQL>
SQL> DECLARE-- from w w  w.j a  v  a2  s. c  o  m
  2    done    BOOLEAN;              -- Initial value is NULL by default
  3    counter NUMBER := 0;
  4  BEGIN
  5    done := FALSE;                -- Assign literal value
  6    WHILE done != TRUE            -- Compare to literal value
  7    LOOP
  8        counter := counter + 1;
  9        done := (counter > 500);  -- Assign value of BOOLEAN expression
 10    END LOOP;
 11    DBMS_OUTPUT.PUT_LINE ('counter: ' || counter);
 12  END;
 13  /
counter: 501

PL/SQL procedure successfully completed.

SQL>

Related Topic