Is there any boolean type in Oracle databases?

ghz 8months ago ⋅ 152 views

Is there any Boolean type in Oracle databases, similar to the BIT datatype in Ms SQL Server?

Answers

Oracle doesn't have a native BOOLEAN data type like some other database systems such as SQL Server. However, Oracle commonly uses a numeric type to represent Boolean values. Traditionally, Oracle uses the NUMBER(1) data type, where 0 represents FALSE and 1 represents TRUE.

For example, you can define a column as follows:

CREATE TABLE example_table (
    id NUMBER PRIMARY KEY,
    is_active NUMBER(1)
);

And you would insert data like:

INSERT INTO example_table (id, is_active) VALUES (1, 1); -- TRUE
INSERT INTO example_table (id, is_active) VALUES (2, 0); -- FALSE

However, starting from Oracle 12c, there's a BOOLEAN data type introduced in PL/SQL, which is used in procedural constructs within Oracle's PL/SQL language. But, this BOOLEAN type cannot be used directly in SQL statements, and it's not a direct equivalent to the BIT data type in SQL Server.