Introduction

The following code creates a procedure, print_boolean, that prints the value of a BOOLEAN variable.

Demo

SQL>
SQL> CREATE OR REPLACE PROCEDURE print_boolean (
  2    b_name   VARCHAR2,-- ww w . j  a v  a  2 s.c  om
  3    b_value  BOOLEAN
  4   ) IS
  5  BEGIN
  6    IF b_value IS NULL THEN
  7      DBMS_OUTPUT.PUT_LINE (b_name || ' = NULL');
  8    ELSIF b_value = TRUE THEN
  9      DBMS_OUTPUT.PUT_LINE (b_name || ' = TRUE');
 10    ELSE
 11      DBMS_OUTPUT.PUT_LINE (b_name || ' = FALSE');
 12    END IF;
 13  END;
 14  /

Procedure created.

SQL>
SQL> DECLARE
  2    PROCEDURE print_x_and_y (
  3      x  BOOLEAN,
  4      y  BOOLEAN
  5    ) IS
  6    BEGIN
  7     print_boolean ('x', x);
  8     print_boolean ('y', y);
  9     print_boolean ('x AND y', x AND y);
 10   END print_x_and_y;
 11
 12  BEGIN
 13   print_x_and_y (FALSE, FALSE);
 14   print_x_and_y (TRUE, FALSE);
 15   print_x_and_y (FALSE, TRUE);
 16   print_x_and_y (TRUE, TRUE);
 17
 18   print_x_and_y (TRUE, NULL);
 19   print_x_and_y (FALSE, NULL);
 20   print_x_and_y (NULL, TRUE);
 21   print_x_and_y (NULL, FALSE);
 22  END;
 23  /
x = FALSE
y = FALSE
x AND y = FALSE
x = TRUE
y = FALSE
x AND y = FALSE
x = FALSE
y = TRUE
x AND y = FALSE
x = TRUE
y = TRUE
x AND y = TRUE
x = TRUE
y = NULL
x AND y = NULL
x = FALSE
y = NULL
x AND y = FALSE
x = NULL
y = TRUE
x AND y = NULL
x = NULL
y = FALSE
x AND y = FALSE

PL/SQL procedure successfully completed.

SQL>

Related Topic