Yesterday I wanted to add a boolean field to an Oracle table. However, there isn’t actually a boolean data type in Oracle. Does anyone here know the best way to simulate a boolean? Googling the subject discovered several approaches
-
Use an integer and just don’t bother assigning anything other than 0 or 1 to it.
-
Use a char field with ‘Y’ or ‘N’ as the only two values.
-
Use an enum with the CHECK constraint.
Do experienced Oracle developers know which approach is preferred/canonical?
I found this link useful.
Here is the paragraph highlighting some of the pros/cons of each approach.
Basically they advocate method number 2, for efficiency’s sake, using
getBoolean()etc.) with a check constraintTheir example: