Boolean Data Type in Oracle Database 23c

Bo English-Wiczling
Oracle Developers
Published in
4 min readJun 12, 2023

In the ever-evolving world of database management systems, improving data handling and querying capabilities is key. One of the latest additions is the boolean data type introduced in Oracle Database 23c. This powerful data type brings several benefits to developers and database administrators, enhancing how boolean values are handled within the Oracle database. In this blog post, we will delve into the key features and advantages of the boolean data type.

The boolean data type in Oracle Database 23c is designed to represent two distinct states: true and false. It offers a more intuitive and expressive way of storing and manipulating logical values within the database. Unlike previous versions of Oracle, which relied on number (0 for false and 1 for true) or character data types (‘Y’ and ’N’) to represent boolean values, Oracle Database 23c provides a dedicated boolean data type, simplifying data modeling and improving query readability.

Oracle Database 23c accepts specific numbers and literals that can be converted to true or false values when working with boolean columns. Here are the accepted values for true and false:

Numbers:

  • The value 0 will be converted to FALSE.
  • Any other number (e.g., 1, -3, 2.657) will be converted to TRUE.

Strings (case insensitive):

  • The strings ‘true’, ‘yes’, ‘on’, ‘1’, ‘t’, and ‘y’ will be converted to TRUE.
  • The strings ‘false’, ‘no’, ‘off’, ‘0’, ‘f’, and ’n’ will be converted to FALSE.

Oracle Database 23c introduces a new syntax to simplify boolean expressions. The following syntax is available:

  • “IS [NOT] TRUE”: This syntax allows you to check if a boolean value is true. For example, you can write “column_name IS TRUE” to check if the value of the column is true.
  • “IS [NOT] FALSE”: This syntax allows you to check if a boolean value is false. For example, you can write “column_name IS FALSE” to check if the value of the column is false.

These new syntax options provide more clarity and readability when working with boolean values. They can be combined with the AND and OR operators to create complex boolean expressions.

Simplified Conditional Expressions

Boolean data types also simplify conditional expressions. Developers can write cleaner and more readable code by directly using boolean variables or columns in conditional statements. This enhances code maintainability and makes it easier to understand the logic behind complex business rules.

For example, instead of writing

select * from person where married = true

you can simplify the statement to

select * from person where married

Also, you can include boolean expression in case statements.

Integration with PL/SQL

The boolean data type seamlessly integrates with Oracle’s procedural language, PL/SQL. PL/SQL developers can take advantage of boolean variables and parameters to improve code clarity and simplify logical operations within stored procedures, functions, and triggers. Boolean data types enable more efficient decision-making and control flow structures in PL/SQL programs.

Migration Assistance with to_boolean Function

To facilitate the migration of existing applications to the boolean data type, Oracle introduced the to_boolean function. This function allows developers to convert numeric or string values to their corresponding boolean representations. For example, you can use the to_boolean function to convert values like 0, ‘true’, and ‘no’ to their boolean equivalents. This simplifies the migration process and ensures data consistency.

Enhanced Data Integrity

By introducing the boolean data type, Oracle Database 23c ensures better data integrity within the database. It allows developers to enforce logical constraints more efficiently, ensuring that only valid boolean values are stored. With boolean columns, the database can enforce constraints such as CHECK constraints, ensuring that only true or false values are allowed, reducing the risk of inconsistent or incorrect data.

Improved Query Performance

The boolean data type in Oracle Database 23c also contributes to enhanced query performance. With dedicated boolean columns you can index this column and querying operations can be optimized, resulting in faster execution times for boolean-based conditions.

Check out https://www.oracle.com/database/free/get-started/ to download Oracle Database 23c Free — Developer Release to get started today!

--

--

Bo English-Wiczling
Oracle Developers

Senior Director, Oracle Database Product Management | DevRel