Search code examples
sqloracle-databasecreate-table

Boolean type - oracle


I'm looking for some help with boolean. I searched around the internet and found out there's no real boolean type in Oracle, but came out with this :

create table tbool (bool char check (bool in (0,1));
insert into tbool values(0);
insert into tbool values(1);

I'm looking to add it to a table like so:

CREATE TABLE Member
(
    mem_id NUMBER(8) CONSTRAINT mem_id_pk PRIMARY KEY,
        mem_registeration DATE,
        (Here I want the boolean, called IsEligble) 
);

I just don't know how to enter it. Any help? thanks in advance!


Solution

  • CREATE TABLE Member
    (
        mem_id NUMBER(8) CONSTRAINT mem_id_pk PRIMARY KEY,
        mem_registeration DATE,
        is_eligible number(1) default 0 not null,
        constraint ck_is_eligible check ( is_eligible in ( 0, 1 ))
    );
    

    (I think. Haven't tested it. Set your default as appropriate for your application.) You can also use 'Y' and 'N' for your pseudo-boolean values. I think it's just a matter of style.