Exploring the New Boolean Data Type in Oracle 23c AI

This exciting release of Boolean Data Type Lab for Oracle Database 23c AI introduces native support for the boolean data type, a game-changer for database developers. With this enhancement, you can natively represent true, false, and null values, simplifying data modeling and making SQL and PL/SQL development more efficient.

To illustrate, let’s recreate a scenario involving a Student Information System, where we’ll track whether students are currently enrolled in courses using the new boolean data type.

This feature enhances developer productivity and makes Oracle Database more intuitive to work with.

Creating a Table With the Boolean Data Type

We will begin by creating a STUDENTS table that includes a boolean column named CURRENTLY_ENROLLED:

SQL

 

Inserting Data With Boolean Values

Now let’s populate the table with sample data using different boolean literals:

SQL

 

Oracle maps various inputs, like 'yes', 'no', 1, and 0 to their corresponding boolean values. Let’s verify the data:

SQL

 

Verifying the data

Querying Boolean Data

Finding Currently Enrolled Students

To retrieve students who are currently enrolled:

SQL

 

Retrieving students who are currently enrolled

Logical Operations on Boolean Columns

Boolean values allow for direct logical operations. For example, filtering students considered “actively enrolled”:

SQL

 

Filtering students considered "actively enrolled""

Finding Non-Enrolled Students

To identify students who are not currently enrolled:

SQL

 

Combining Boolean Logic With Other Conditions

Let’s retrieve students who are either enrolled or whose names start with ‘A’:

SQL

 

Retrieving students who are either enrolled or whose names start with 'A'

Updating Boolean Values

Marking a Student as Enrolled

Suppose we want to update Bob’s enrollment status:

SQL

 

Using PL/SQL With Boolean Data Type

PL/SQL seamlessly integrates with the new boolean data type. Let’s add a new student:

SQL

 

Let’s validate the newly inserted data.

Validating the newly inserted data

Conclusion

The introduction of the boolean data type in Oracle Database 23c AI simplifies database design and improves the readability and maintainability of your SQL and PL/SQL code. Reducing reliance on workarounds like numeric or character codes empowers developers to write cleaner and more intuitive queries.

Whether managing a Student Information System or any other application, the boolean data type makes handling logical values straightforward and robust. Get hands-on experience today, and see how this feature can elevate your database projects.

Source:
https://dzone.com/articles/exploring-the-new-boolean-data-type-in-oracle-23c-ai