Boolean data type with If statement : Boolean « Data Type « Oracle PL / SQL






Boolean data type with If statement

   
SQL> SET SERVEROUTPUT ON SIZE 1000000
SQL> <<default_test>>
  2  DECLARE
  3     lv_first_num      NUMBER(10) DEFAULT 0;    -- Defaulted to 0
  4     lv_second_num     NUMBER(10) := 10;        -- Defaulted to 10
  5     lv_third_num      NUMBER(10);              -- Defaulted to NULL
  6     lv_processed_bln  BOOLEAN DEFAULT FALSE;   -- Defaulted to FALSE
  7     lv_complete_bln1  BOOLEAN;                 -- Defaulted to NULL
  8     lv_complete_bln2  BOOLEAN;                 -- Defaulted to NULL
  9  BEGIN
 10     DBMS_OUTPUT.PUT_LINE('lv_first_num:      ' ||
 11               TO_CHAR(lv_first_num)  ||
 12               CHR(10) || 'lv_second_num:     ' ||
 13               TO_CHAR(lv_second_num) ||
 14               CHR(10) || 'lv_third_num:      ' ||
 15               TO_CHAR(lv_third_num)  ||
 16               CHR(10) || 'lv_processed_bln:  ' || 'FALSE' ||
 17               CHR(10) || 'lv_complete_bln1:  ' || ''      ||
 18               CHR(10) || 'lv_complete_bln2:  ' || ''      ||
 19               CHR(10) ||
 20               'default_test.lv_second_num: ' ||
 21               TO_CHAR(default_test.lv_second_num) || CHR(10));
 22     DBMS_OUTPUT.PUT_LINE('Is lv_second_num > lv_third_num?');
 23     IF lv_second_num > lv_third_num THEN
 24        DBMS_OUTPUT.PUT_LINE('lv_second_num > lv_third_num' || CHR(10));
 25     ELSE
 26        DBMS_OUTPUT.PUT_LINE('lv_second_num < lv_third_num' || CHR(10));
 27     END IF;
 28     DBMS_OUTPUT.PUT_LINE('Is lv_first_num = lv_third_num?');
 29     IF lv_first_num = lv_third_num THEN
 30        DBMS_OUTPUT.PUT_LINE('lv_first_num = lv_third_num');
 31     ELSE
 32        DBMS_OUTPUT.PUT_LINE('lv_first_num <> lv_third_num');
 33     END IF;
 34     DBMS_OUTPUT.PUT_LINE('Is lv_complete_bln1 = TRUE?');
 35     IF lv_complete_bln1 THEN
 36        DBMS_OUTPUT.PUT_LINE('lv_complete_bln1 = TRUE');
 37     ELSE
 38        DBMS_OUTPUT.PUT_LINE('lv_complete_bln1 <> TRUE');
 39     END IF;
 40     DBMS_OUTPUT.PUT_LINE('Is NOT lv_complete_bln1 = TRUE?');
 41     IF NOT lv_complete_bln1 THEN
 42        DBMS_OUTPUT.PUT_LINE('NOT lv_complete_bln1 = TRUE');
 43     ELSE
 44        DBMS_OUTPUT.PUT_LINE('NOT lv_complete_bln1 <> TRUE');
 45     END IF;
 46     DBMS_OUTPUT.PUT_LINE('Is lv_complete_bln1 = lv_complet_bln2?');
 47     IF lv_complete_bln1 = lv_complete_bln2 THEN
 48        DBMS_OUTPUT.PUT_LINE('lv_complete_bln1 = lv_complete_bln2');
 49     ELSE
 50        DBMS_OUTPUT.PUT_LINE('lv_complete_bln1 <> lv_complete_bln2');
 51     END IF;
 52  END default_test;
 53  /
lv_first_num:      0
lv_second_num:     10
lv_third_num:
lv_processed_bln:  FALSE
lv_complete_bln1:
lv_complete_bln2:
default_test.lv_second_num: 10

Is lv_second_num > lv_third_num?
lv_second_num < lv_third_num

Is lv_first_num = lv_third_num?
lv_first_num <> lv_third_num
Is lv_complete_bln1 = TRUE?
lv_complete_bln1 <> TRUE
Is NOT lv_complete_bln1 = TRUE?
NOT lv_complete_bln1 <> TRUE
Is lv_complete_bln1 = lv_complet_bln2?
lv_complete_bln1 <> lv_complete_bln2

PL/SQL procedure successfully completed.

SQL>

   
    
  








Related examples in the same category

1.PL/SQL BOOLEAN datatypes accept only TRUE, FALSE, NULL
2.Define and use boolean value
3.Use the NVL() against a non-initialized BOOLEAN variable:
4.Boolean literals
5.Boolean expressions in where clause
6.Assign a value to a variable of type boolean. Don't use quotes around the value like this