Is there any Boolean type in Oracle databases, similar to the BIT datatype in Ms SQL Server?
11 Answers
Not only is the boolean datatype missing in Oracle's SQL (not PL/SQL), but they also have no clear recommendation about what to use instead. See this thread on asktom. From recommending CHAR(1) 'Y'/'N' they switch to NUMBER(1) 0/1 when someone points out that 'Y'/'N' depends on the English language, while e.g. German programmers might use 'J'/'N' instead.
The worst thing is that they defend this stupid decision just like they defend the ''=NULL stupidity.
Nope.
Can use:
IS_COOL NUMBER(1,0)
1 - true
0 - false
--- enjoy Oracle
Or use char Y/N as described here
No, there isn't a boolean type in Oracle Database, but you can do this way:
You can put a check constraint on a column.
If your table hasn't a check column, you can add it:
ALTER TABLE table_name
ADD column_name_check char(1) DEFAULT '1';When you add a register, by default this column get 1.
Here you put a check that limit the column value, just only put 1 or 0
ALTER TABLE table_name ADD
CONSTRAINT name_constraint
column_name_check (ONOFF in ( '1', '0' ));If you are using Java with Hibernate then using NUMBER(1,0) is the best approach. As you can see in here, this value is automatically translated to Boolean by Hibernate.
ints instead). We should definitely go back to those in code. Additionally, the argument completely falls apart if the data types between table columns and result columns (from aSELECT) are shared, since it is absolutely appropriate to return a boolean as a computed result sometimes even given the rest of the argument. - jpmc26DATEtype - imagine having to deal with string representations of dates all the time :) - Jeffrey Kemp