DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Newsletter
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Grounding AI Agents in Governed Data
  • Custom Model Context Protocol (MCP) for NL2SQL: A Rigorous Evaluation Framework on Oracle Database
  • Chat with Your Oracle Database: SQLcl MCP + GitHub Copilot
  • SELECT AI Query Integration Using Oracle Autonomous Database 26AI and OpenAI

Trending

  • When Production Stops Moving: Running Claude Code Across a Distributed Enterprise Integration Team
  • Beyond the Wall of Charts: How Advanced Observability Displaced the Telemetry Dashboard
  • Full-Text Search Meets the Graph: Apache Lucene Inside Neo4j
  • A Non-Expiring AKS Deployment Token Could Read Secrets Across Three Namespaces

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

  1. DZone
  2. Data Engineering
  3. Databases
  4. Exploring the New Boolean Data Type in Oracle 23c AI

Exploring the New Boolean Data Type in Oracle 23c AI

Oracle 23c AI introduces native support for the boolean data type, enabling straightforward representation of true, false, and null values in SQL and PL/SQL.

By 
arvind toorpu
DZone Core CORE ·
Dec. 19, 24 · Tutorial
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
5.5K Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in

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
 
DROP TABLE IF EXISTS STUDENTS CASCADE CONSTRAINT;

-- Create STUDENTS table with a boolean column
CREATE TABLE STUDENTS (
    STUDENT_ID         NUMBER PRIMARY KEY,
    NAME               VARCHAR2(100),
    COURSE             VARCHAR2(100),
    CURRENTLY_ENROLLED BOOLEAN
);


Inserting Data With Boolean Values

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

SQL
 
-- Insert sample data using boolean values and accepted boolean literals
INSERT INTO STUDENTS VALUES (1, 'Alice', 'Mathematics', TRUE),
                             (2, 'Bob', 'Physics', FALSE),
                             (3, 'Charlie', 'Chemistry', 'yes'),
                             (4, 'Diana', 'Biology', 'no'),
                             (5, 'Eve', 'Computer Science', 'on'),
                             (6, 'Frank', 'Statistics', 'off'),
                             (7, 'Grace', 'History', 1),
                             (8, 'Hank', 'Philosophy', 0),
                             (9, 'Ivy', 'Engineering', NULL);


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

SQL
 
SELECT student_id, name, course, currently_enrolled
FROM students;

Verifying the data


Querying Boolean Data

Finding Currently Enrolled Students

To retrieve students who are currently enrolled:

SQL
 
SELECT student_id, name, course
FROM students
WHERE currently_enrolled = TRUE;

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
 
SELECT student_id, name, course
FROM students
WHERE currently_enrolled AND TRUE;

Filtering students considered "actively enrolled""

Finding Non-Enrolled Students

To identify students who are not currently enrolled:

SQL
 
SELECT student_id, name, course
FROM students
WHERE NOT currently_enrolled;


Combining Boolean Logic With Other Conditions

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

SQL
 
SELECT student_id, name, course
FROM students
WHERE currently_enrolled OR name LIKE 'A%';

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
 
UPDATE students
SET currently_enrolled = TRUE
WHERE student_id = 2;

-- Verify the update
SELECT name, currently_enrolled
FROM students
WHERE student_id = 2;


Using PL/SQL With Boolean Data Type

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

SQL
 
DECLARE
    l_student_id NUMBER := 10;
    l_name       VARCHAR2(100) := 'John';
    l_course     VARCHAR2(100) := 'Data Science';
    l_enrolled   BOOLEAN := TRUE;
BEGIN
    INSERT INTO students (student_id, name, course, currently_enrolled)
    VALUES (l_student_id, l_name, l_course, l_enrolled);

    COMMIT;
END;


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.

AI Database Oracle Database sql

Opinions expressed by DZone contributors are their own.

Related

  • Grounding AI Agents in Governed Data
  • Custom Model Context Protocol (MCP) for NL2SQL: A Rigorous Evaluation Framework on Oracle Database
  • Chat with Your Oracle Database: SQLcl MCP + GitHub Copilot
  • SELECT AI Query Integration Using Oracle Autonomous Database 26AI and OpenAI

Partner Resources

×

Comments

Loading comments

The comments didn't load

Please try again in a moment.

Likes

Loading

The next likes didn't load. Please try again.

The likes didn't load

Please try again in a moment.

See who liked this

Log in or join DZone for free to see who liked this article.

Log in Join for free
  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook