The Oracle PL/SQL Boolean data type is a data type that can store two values: TRUE or FALSE.
The Boolean data type is often used in programming to store values that can only be one of two options, such as true or false.
Syntax
To declare a variable with the Boolean data type, you use the following syntax:
variable_name BOOLEAN;
Examples
For example, the following declaration creates a Boolean variable named is_admin that can store two values: TRUE or FALSE:
is_admin BOOLEAN;
When you assign a value to a Boolean variable, you can use the keywords TRUE or FALSE, or the numbers 1 or 0. For example:
is_admin := TRUE; is_admin := FALSE; is_admin := 1; -- same as TRUE is_admin := 0; -- same as FALSE
The following example uses the Oracle PL/SQL Boolean data type:
DECLARE is_admin BOOLEAN := TRUE; BEGIN IF is_admin = FALSE THEN -- do something here END IF; END;
In the example above, the IF statement will only execute if the is_admin variable is FALSE. If the is_admin variable is TRUE, the IF statement will not be executed.
You can also use the Oracle PL/SQL Boolean data type in assignments and comparisons. The following example uses the Oracle PL/SQL Boolean data type in an assignment:
DECLARE is_admin BOOLEAN := TRUE; BEGIN is_admin := FALSE; -- assignment END;
In the example above, the is_admin variable is assigned the value FALSE.